Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check program input #23

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions headers/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Configuration {

std::string getClientSecret() const;

void validate_configuration_values();

private:
std::string language;
std::string topic;
Expand All @@ -60,6 +62,10 @@ class Configuration {
std::string label;
std::string clientId;
std::string clientSecret;
std::vector<std::string> allowedTopicValues = {"GENERIC", "BANKING", "TELCO", "INSURANCE"};
std::vector<std::string> allowedLanguageValues = {"en-US", "en-GB", "pt-BR", "es", "es-419", "tr", "ja", "fr", "fr-CA", "de", "it"};
std::vector<std::string> allowedAsrVersionValues = {"V1", "V2"};

};


Expand Down
28 changes: 26 additions & 2 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "Configuration.h"

#include "gRpcExceptions.h"
#include "logger.h"

#include <cxxopts.hpp>


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() {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -107,4 +108,27 @@ 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 sample rate value. Allowed values: 8000 or 1600");
}

if (std::find(allowedTopicValues.begin(), allowedTopicValues.end(), topic) == allowedTopicValues.end())
{
throw std::runtime_error("Unsupported topic value. Allowed values: GENERIC, BANKING, TELCO, INSURANCE");
}

if (std::find(allowedLanguageValues.begin(), allowedLanguageValues.end(), language) == allowedLanguageValues.end())
{
throw std::runtime_error("Unsupported language value. Allowed values: en-US, en-GB, pt-BR, es, es-419, tr, ja, fr, fr-CA, de, it");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be best to use the allowedValues vector to automatically fill this string so we do not make a mistake when we add a new language

}

if (std::find(allowedAsrVersionValues.begin(), allowedAsrVersionValues.end(), asrVersion) == allowedAsrVersionValues.end())
{
throw std::runtime_error("Unsupported asr version value. Allowed values: V1, V2");
}

}
1 change: 1 addition & 0 deletions src/RecognitionClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading