diff --git a/src/audio_output_alsa.cc b/src/audio_output_alsa.cc index c5cb51b..6236a71 100644 --- a/src/audio_output_alsa.cc +++ b/src/audio_output_alsa.cc @@ -104,7 +104,6 @@ bool AudioOutputALSA::Start() { snd_pcm_drain(pcm_handle); snd_pcm_close(pcm_handle); })); - std::cout << "AudioOutputALSA Start() succeeded" << std::endl; return true; } @@ -118,7 +117,6 @@ void AudioOutputALSA::Stop() { isRunning = false; alsaThread->join(); alsaThread.reset(nullptr); - std::cout << "AudioOutputALSA Stop() succeeded" << std::endl; } void AudioOutputALSA::Send(std::shared_ptr> data) { diff --git a/src/run_assistant.cc b/src/run_assistant.cc index c932e87..678041a 100644 --- a/src/run_assistant.cc +++ b/src/run_assistant.cc @@ -62,6 +62,8 @@ static const std::string kLanguageCode = "en-US"; static const std::string kDeviceInstanceId = "default"; static const std::string kDeviceModelId = "default"; +bool verbose = false; + // Creates a channel to be connected to Google. std::shared_ptr CreateChannel(const std::string& host) { std::ifstream file("robots.pem"); @@ -69,13 +71,16 @@ std::shared_ptr CreateChannel(const std::string& host) { buffer << file.rdbuf(); std::string roots_pem = buffer.str(); - std::cout << "assistant_sdk robots_pem: " << roots_pem << std::endl; + if (verbose) { + std::clog << "assistant_sdk robots_pem: " << roots_pem << std::endl; + } ::grpc::SslCredentialsOptions ssl_opts = {roots_pem, "", ""}; auto creds = ::grpc::SslCredentials(ssl_opts); std::string server = host + ":443"; - std::cout << "assistant_sdk CreateCustomChannel(" << server << ", creds, arg)" - + if (verbose) { + std::clog << "assistant_sdk CreateCustomChannel(" << server << ", creds, arg)" << std::endl << std::endl; + } ::grpc::ChannelArguments channel_args; return CreateCustomChannel(server, creds, channel_args); } @@ -101,13 +106,14 @@ bool GetCommandLineFlags( {"credentials_type", required_argument, nullptr, 'c'}, {"api_endpoint", required_argument, nullptr, 'e'}, {"locale", required_argument, nullptr, 'l'}, + {"verbose", no_argument, nullptr, 'v'}, {nullptr, 0, nullptr, 0} }; *api_endpoint = ASSISTANT_ENDPOINT; while (true) { int option_index; int option_char = - getopt_long(argc, argv, "i:t:f:c:e:l", long_options, &option_index); + getopt_long(argc, argv, "i:t:f:c:e:l:v", long_options, &option_index); if (option_char == -1) { break; } @@ -135,6 +141,9 @@ bool GetCommandLineFlags( case 'l': *locale = optarg; break; + case 'v': + verbose = true; + break; default: PrintUsage(); return false; @@ -219,8 +228,10 @@ int main(int argc, char** argv) { std::shared_ptr> stream(std::move(assistant->Assist(&context))); // Write config in first stream. - std::cout << "assistant_sdk wrote first request: " - << request.ShortDebugString() << std::endl; + if (verbose) { + std::clog << "assistant_sdk wrote first request: " + << request.ShortDebugString() << std::endl; + } stream->Write(request); if (!audio_input_source.empty()) { @@ -259,8 +270,13 @@ int main(int argc, char** argv) { #endif // Read responses. - std::cout << "assistant_sdk waiting for response ... " << std::endl; + if (verbose) { + std::clog << "assistant_sdk waiting for response ... " << std::endl; + } AssistResponse response; + if (verbose) { + std::clog << "assistant_sdk Got a response \n"; + } while (stream->Read(&response)) { // Returns false when no more to read. if ((response.has_audio_out() || response.event_type() == AssistResponse_EventType_END_OF_UTTERANCE) @@ -284,15 +300,17 @@ int main(int argc, char** argv) { for (int i = 0; i < response.speech_results_size(); i++) { google::assistant::embedded::v1alpha2::SpeechRecognitionResult result = response.speech_results(i); - std::cout << "assistant_sdk request: \n" - << result.transcript() << " (" - << std::to_string(result.stability()) - << ")" << std::endl; + if (verbose) { + std::clog << "assistant_sdk request: \n" + << result.transcript() << " (" + << std::to_string(result.stability()) + << ")" << std::endl; + } } if (response.dialog_state_out().supplemental_display_text().size() > 0) { // CUSTOMIZE: render spoken response on screen - std::cout << "assistant_sdk display text: \n" - << response.dialog_state_out().supplemental_display_text() + std::clog << "assistant_sdk response:" << std::endl; + std::cout << response.dialog_state_out().supplemental_display_text() << std::endl; } } diff --git a/tests/integration_en_us.sh b/tests/integration_en_us.sh new file mode 100755 index 0000000..1c6388a --- /dev/null +++ b/tests/integration_en_us.sh @@ -0,0 +1,9 @@ +# Tests that the command "how do you say hi in spanish" +# will return "Hola" to verify the Assistant SDK +# end-to-end. +set -e +set -x + +./run_assistant --text_input "how do you say hi in spanish" \ + --credentials_file ./credentials.json --credentials_type USER_ACCOUNT \ + --verbose | grep "Hola" diff --git a/tests/integration_fr.sh b/tests/integration_fr.sh new file mode 100755 index 0000000..ebb9507 --- /dev/null +++ b/tests/integration_fr.sh @@ -0,0 +1,9 @@ +# Tests that the command "how do you say hello in spanish" +# will return "buenos dias" to verify the Assistant SDK +# end-to-end. +set -e +set -x + +./run_assistant --text_input "comment dit-on bonjour en español" \ + --credentials_file ./credentials.json --credentials_type USER_ACCOUNT \ + --locale "fr-FR" --verbose | grep "Buenos dias" diff --git a/tests/test_all.sh b/tests/test_all.sh new file mode 100755 index 0000000..f1d87e3 --- /dev/null +++ b/tests/test_all.sh @@ -0,0 +1,12 @@ +# Run all tests +# Expected usage: +# > cpp$ ./tests/test_all.sh +set -e +set -x + +# Verify it builds +./tests/build.sh + +# After building, run end-to-end tests +./tests/integration_en_us.sh +./tests/integration_fr.sh