diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18d4191..1e8d391 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: run: conan install cmake/3.16.4@ -g=virtualrunenv working-directory: ./build - name: Build - run: conan install -s compiler.libcxx=libstdc++ .. && cmake .. && cmake --build ./ --target all --parallel + run: conan install -s compiler.libcxx=libstdc++ --build=missing .. && cmake .. && cmake --build ./ --target all --parallel working-directory: ./build - name: Test run: ctest --parallel diff --git a/headers/Configuration.h b/headers/Configuration.h index 9a0f2b6..75deb78 100644 --- a/headers/Configuration.h +++ b/headers/Configuration.h @@ -45,7 +45,12 @@ class Configuration { std::string getClientSecret() const; + void validate_configuration_values(); + private: + + void validate_string_value(const char *name, const std::string &value, const std::vector &allowedValues); + std::string language; std::string topic; std::string grammarPath; @@ -60,6 +65,10 @@ class Configuration { std::string label; std::string clientId; std::string clientSecret; + std::vector allowedTopicValues = {"GENERIC", "BANKING", "TELCO", "INSURANCE"}; + std::vector allowedLanguageValues = {"en-US", "en-GB", "pt-BR", "es", "es-419", "tr", "ja", "fr", "fr-CA", "de", "it"}; + std::vector allowedAsrVersionValues = {"V1", "V2"}; + }; diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 7de6e8e..cedafc0 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -1,11 +1,11 @@ #include "Configuration.h" - #include "gRpcExceptions.h" +#include "logger.h" #include -Configuration::Configuration() : host("csr.api.speechcenter.verbio.com"), topic("generic"), language("en-US"), +Configuration::Configuration() : host("us.speechcenter.verbio.com"), topic("generic"), language("en-US"), sampleRate(8000) {} Configuration::Configuration(int argc, char **argv) : Configuration() { @@ -51,6 +51,7 @@ void Configuration::parse(int argc, char **argv) { if ((parsedOptions.count("t") == 0) == (parsedOptions.count("g") == 0)) throw GrpcException("Topic and grammar options are mutually exclusive and at least one is needed."); + validate_configuration_values(); } std::string Configuration::getAudioPath() const { @@ -107,4 +108,29 @@ std::string Configuration::getClientId() const { std::string Configuration::getClientSecret() const { return clientSecret; +} + +void Configuration::validate_configuration_values() { + + if(sampleRate != 8000 and sampleRate != 16000) { + throw std::runtime_error("Unsupported parameter value. Allowed values sample rate: 8000 1600"); + } + + validate_string_value("topic", topic, allowedTopicValues); + validate_string_value("language", language, allowedLanguageValues); + validate_string_value("asr version", asrVersion, allowedAsrVersionValues); +} + + +void Configuration::validate_string_value(const char *name, const std::string &value, const std::vector &allowedValues) { + if (std::find(allowedValues.begin(), allowedValues.end(), value) == allowedValues.end()) + { + std::stringstream ss; + std::copy(allowedValues.begin(), allowedValues.end(), std::ostream_iterator(ss, " ")); + std::string allowedValuesList = ss.str(); + std::string nameString(name); + std::string errorMessage("Unsupported parameter value. Allowed values for "); + std::string exceptionMessage = errorMessage + nameString.append(": ") + allowedValuesList; + throw std::runtime_error(exceptionMessage); + } } \ No newline at end of file diff --git a/src/RecognitionClient.cpp b/src/RecognitionClient.cpp index ffb8991..9e81521 100644 --- a/src/RecognitionClient.cpp +++ b/src/RecognitionClient.cpp @@ -257,6 +257,7 @@ RecognitionClient::convertTopic(const std::string &topicName) { auto topicIter = validTopics.find(topicUpper); if (topicIter == validTopics.end()) { + ERROR("Unsupported topic: {}", topicName); throw UnknownTopicModel(topicUpper); } diff --git a/src/main.cpp b/src/main.cpp index e0aff42..2148064 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) { Configuration configuration(argc, argv); RecognitionClient client(configuration); client.performStreamingRecognition(); - } catch (GrpcException &e) { + } catch (std::exception &e) { ERROR(e.what()); return -1; }