Skip to content

Commit 7120c5d

Browse files
committed
Removes credentials_type flag
This flag is unnecessary since USER_ACCOUNT was the only possible value and that was not used in the request or response. This removes the flag and renames --credentials_file to --credentials Bug: 80474131 Change-Id: Icbca28d23f7eb36a7d3c25d905808c5223229754
1 parent 368103e commit 7120c5d

File tree

7 files changed

+37
-80
lines changed

7 files changed

+37
-80
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,32 @@ make run_assistant
8585
7. Start one of the `run_assistant` samples:
8686

8787
```bash
88-
./run_assistant_file --input ./resources/weather_in_mountain_view.raw --credentials_file ./credentials.json
88+
./run_assistant_file --input ./resources/weather_in_mountain_view.raw --audio_output ./response.wav --credentials ./credentials.json
89+
aplay ./response.wav --rate=16000 --format=S16_LE
8990
```
9091

9192
On a Linux workstation, you can alternatively use ALSA for audio input:
9293

9394
```bash
94-
./run_assistant_audio --credentials_file ./credentials.json
95+
./run_assistant_audio --credentials ./credentials.json
9596
```
9697

9798
You can use a text-based query instead of audio. This allows you to continually enter text queries to the Assistant.
9899

99100
```bash
100-
./run_assistant_text --credentials_file ./credentials.json
101+
./run_assistant_text --credentials ./credentials.json
101102
```
102103

103104
This takes input from `cin`, so you can send data to the program when it starts.
104105

105106
```bash
106-
echo "what time is it" | ./run_assistant_text --credentials_file ./credentials.json
107+
echo "what time is it" | ./run_assistant_text --credentials ./credentials.json
107108
```
108109

109110
To change the locale, include a `locale` parameter:
110111

111112
```bash
112-
echo "Bonjour" | ./run_assistant_text --credentials_file ./credentials.json --locale "fr-FR"
113+
echo "Bonjour" | ./run_assistant_text --credentials ./credentials.json --locale "fr-FR"
113114
```
114115

115116
Default Assistant gRPC API endpoint is embeddedassistant.googleapis.com. If you want to test with a custom Assistant gRPC API endpoint, you can pass an extra "--api_endpoint CUSTOM_API_ENDPOINT" to run_assistant.

src/run_assistant_audio.cc

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,17 @@ std::shared_ptr<Channel> CreateChannel(const std::string& host) {
8787

8888
void PrintUsage() {
8989
std::cerr << "Usage: ./run_assistant_audio "
90-
<< "--credentials_file <credentials_file> "
91-
<< "[--credentials_type <" << kCredentialsTypeUserAccount << ">] "
90+
<< "--credentials <credentials_file> "
9291
<< "[--api_endpoint <API endpoint>] "
9392
<< "[--locale <locale>]"
9493
<< std::endl;
9594
}
9695

9796
bool GetCommandLineFlags(
9897
int argc, char** argv, std::string* credentials_file_path,
99-
std::string* credentials_type, std::string* api_endpoint,
100-
std::string* locale) {
98+
std::string* api_endpoint, std::string* locale) {
10199
const struct option long_options[] = {
102-
{"credentials_file", required_argument, nullptr, 'f'},
103-
{"credentials_type", required_argument, nullptr, 'c'},
100+
{"credentials", required_argument, nullptr, 'c'},
104101
{"api_endpoint", required_argument, nullptr, 'e'},
105102
{"locale", required_argument, nullptr, 'l'},
106103
{"verbose", no_argument, nullptr, 'v'},
@@ -110,22 +107,13 @@ bool GetCommandLineFlags(
110107
while (true) {
111108
int option_index;
112109
int option_char =
113-
getopt_long(argc, argv, "f:c:e:l:v", long_options, &option_index);
110+
getopt_long(argc, argv, "c:e:l:v", long_options, &option_index);
114111
if (option_char == -1) {
115112
break;
116113
}
117114
switch (option_char) {
118-
case 'f':
119-
*credentials_file_path = optarg;
120-
break;
121115
case 'c':
122-
*credentials_type = optarg;
123-
if (*credentials_type != kCredentialsTypeUserAccount) {
124-
std::cerr << "Invalid credentials_type: \"" << *credentials_type
125-
<< "\". Should be \"" << kCredentialsTypeUserAccount
126-
<< "\"" << std::endl;
127-
return false;
128-
}
116+
*credentials_file_path = optarg;
129117
break;
130118
case 'e':
131119
*api_endpoint = optarg;
@@ -145,8 +133,7 @@ bool GetCommandLineFlags(
145133
}
146134

147135
int main(int argc, char** argv) {
148-
std::string credentials_file_path, credentials_type,
149-
api_endpoint, locale;
136+
std::string credentials_file_path, api_endpoint, locale;
150137
#ifndef ENABLE_ALSA
151138
std::cerr << "ALSA audio input is not supported on this platform."
152139
<< std::endl;
@@ -157,14 +144,10 @@ int main(int argc, char** argv) {
157144
// https://github.com/grpc/grpc/issues/11366#issuecomment-328595941
158145
grpc_init();
159146
if (!GetCommandLineFlags(argc, argv, &credentials_file_path,
160-
&credentials_type, &api_endpoint, &locale)) {
147+
&api_endpoint, &locale)) {
161148
return -1;
162149
}
163150

164-
if (credentials_type.empty()) {
165-
credentials_type = kCredentialsTypeUserAccount; // Default is USER_ACCOUNT
166-
}
167-
168151
while (true) {
169152
// Create an AssistRequest
170153
AssistRequest request;

src/run_assistant_file.cc

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,21 @@ std::shared_ptr<Channel> CreateChannel(const std::string& host) {
7878
void PrintUsage() {
7979
std::cerr << "Usage: ./run_assistant_file "
8080
<< "--input <audio_file> "
81-
<< "--credentials_file <credentials_file> "
82-
<< "[--credentials_type <" << kCredentialsTypeUserAccount << ">] "
81+
<< "--output <audio_file> "
82+
<< "--credentials <credentials_file> "
8383
<< "[--api_endpoint <API endpoint>] "
8484
<< "[--locale <locale>]"
8585
<< std::endl;
8686
}
8787

8888
bool GetCommandLineFlags(
89-
int argc, char** argv, std::string* audio_input, std::string* credentials_file_path,
90-
std::string* credentials_type, std::string* api_endpoint,
89+
int argc, char** argv, std::string* audio_input, std::string* audio_output,
90+
std::string* credentials_file_path, std::string* api_endpoint,
9191
std::string* locale) {
9292
const struct option long_options[] = {
9393
{"input", required_argument, nullptr, 'i'},
94-
{"credentials_file", required_argument, nullptr, 'f'},
95-
{"credentials_type", required_argument, nullptr, 'c'},
94+
{"output", required_argument, nullptr, 'o'},
95+
{"credentials", required_argument, nullptr, 'c'},
9696
{"api_endpoint", required_argument, nullptr, 'e'},
9797
{"locale", required_argument, nullptr, 'l'},
9898
{"verbose", no_argument, nullptr, 'v'},
@@ -102,25 +102,19 @@ bool GetCommandLineFlags(
102102
while (true) {
103103
int option_index;
104104
int option_char =
105-
getopt_long(argc, argv, "i:f:c:e:l:v", long_options, &option_index);
105+
getopt_long(argc, argv, "i:o:c:e:l:v", long_options, &option_index);
106106
if (option_char == -1) {
107107
break;
108108
}
109109
switch (option_char) {
110110
case 'i':
111111
*audio_input = optarg;
112112
break;
113-
case 'f':
114-
*credentials_file_path = optarg;
113+
case 'o':
114+
*audio_output = optarg;
115115
break;
116116
case 'c':
117-
*credentials_type = optarg;
118-
if (*credentials_type != kCredentialsTypeUserAccount) {
119-
std::cerr << "Invalid credentials_type: \"" << *credentials_type
120-
<< "\". Should be \"" << kCredentialsTypeUserAccount
121-
<< "\"" << std::endl;
122-
return false;
123-
}
117+
*credentials_file_path = optarg;
124118
break;
125119
case 'e':
126120
*api_endpoint = optarg;
@@ -140,20 +134,16 @@ bool GetCommandLineFlags(
140134
}
141135

142136
int main(int argc, char** argv) {
143-
std::string audio_input_source, credentials_file_path, credentials_type,
137+
std::string audio_input_source, audio_output_source, credentials_file_path,
144138
api_endpoint, locale;
145139
// Initialize gRPC and DNS resolvers
146140
// https://github.com/grpc/grpc/issues/11366#issuecomment-328595941
147141
grpc_init();
148-
if (!GetCommandLineFlags(argc, argv, &audio_input_source, &credentials_file_path,
149-
&credentials_type, &api_endpoint, &locale)) {
142+
if (!GetCommandLineFlags(argc, argv, &audio_input_source, &audio_output_source, &credentials_file_path,
143+
&api_endpoint, &locale)) {
150144
return -1;
151145
}
152146

153-
if (credentials_type.empty()) {
154-
credentials_type = kCredentialsTypeUserAccount; // Default is USER_ACCOUNT
155-
}
156-
157147
// Create an AssistRequest
158148
AssistRequest request;
159149
auto* assist_config = request.mutable_config();

src/run_assistant_text.cc

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,17 @@ std::shared_ptr<Channel> CreateChannel(const std::string& host) {
7777

7878
void PrintUsage() {
7979
std::cerr << "Usage: ./run_assistant_text "
80-
<< "--credentials_file <credentials_file> "
81-
<< "[--credentials_type <" << kCredentialsTypeUserAccount << ">] "
80+
<< "--credentials <credentials_file> "
8281
<< "[--api_endpoint <API endpoint>] "
8382
<< "[--locale <locale>]"
8483
<< std::endl;
8584
}
8685

8786
bool GetCommandLineFlags(
8887
int argc, char** argv, std::string* credentials_file_path,
89-
std::string* credentials_type, std::string* api_endpoint,
90-
std::string* locale) {
88+
std::string* api_endpoint, std::string* locale) {
9189
const struct option long_options[] = {
92-
{"credentials_file", required_argument, nullptr, 'f'},
93-
{"credentials_type", required_argument, nullptr, 'c'},
90+
{"credentials", required_argument, nullptr, 'c'},
9491
{"api_endpoint", required_argument, nullptr, 'e'},
9592
{"locale", required_argument, nullptr, 'l'},
9693
{"verbose", no_argument, nullptr, 'v'},
@@ -100,22 +97,13 @@ bool GetCommandLineFlags(
10097
while (true) {
10198
int option_index;
10299
int option_char =
103-
getopt_long(argc, argv, "f:c:e:l:v", long_options, &option_index);
100+
getopt_long(argc, argv, "c:e:l:v", long_options, &option_index);
104101
if (option_char == -1) {
105102
break;
106103
}
107104
switch (option_char) {
108-
case 'f':
109-
*credentials_file_path = optarg;
110-
break;
111105
case 'c':
112-
*credentials_type = optarg;
113-
if (*credentials_type != kCredentialsTypeUserAccount) {
114-
std::cerr << "Invalid credentials_type: \"" << *credentials_type
115-
<< "\". Should be \"" << kCredentialsTypeUserAccount
116-
<< "\"" << std::endl;
117-
return false;
118-
}
106+
*credentials_file_path = optarg;
119107
break;
120108
case 'e':
121109
*api_endpoint = optarg;
@@ -135,21 +123,15 @@ bool GetCommandLineFlags(
135123
}
136124

137125
int main(int argc, char** argv) {
138-
std::string credentials_file_path, credentials_type,
139-
api_endpoint, locale, text_input_source;
126+
std::string credentials_file_path, api_endpoint, locale, text_input_source;
140127
// Initialize gRPC and DNS resolvers
141128
// https://github.com/grpc/grpc/issues/11366#issuecomment-328595941
142129
grpc_init();
143130
if (!GetCommandLineFlags(argc, argv, &credentials_file_path,
144-
&credentials_type, &api_endpoint, &locale)) {
131+
&api_endpoint, &locale)) {
145132
return -1;
146133
}
147134

148-
if (credentials_type.empty()) {
149-
credentials_type = kCredentialsTypeUserAccount; // Default is USER_ACCOUNT
150-
}
151-
152-
153135
while (std::getline(std::cin, text_input_source)) {
154136
// Create an AssistRequest
155137
AssistRequest request;

tests/integration_audio_file.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ set -e
55
set -x
66

77
./run_assistant_file --input ./resources/weather_in_mountain_view.raw \
8-
--credentials_file ./credentials.json \
8+
--output /tmp/google-assistant-sdk-audio-output.raw \
9+
--credentials ./credentials.json \
910
| grep "Mountain View"

tests/integration_en_us.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -e
55
set -x
66

77
echo "how do you say hi in spanish" | ./run_assistant_text \
8-
--credentials_file ./credentials.json --verbose | grep "Hola"
8+
--credentials ./credentials.json --verbose | grep "Hola"

tests/integration_fr.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ set -e
55
set -x
66

77
echo "comment dit-on bonjour en español" | ./run_assistant_text \
8-
--credentials_file ./credentials.json \
8+
--credentials ./credentials.json \
99
--locale "fr-FR" --verbose | grep "Buenos dias"

0 commit comments

Comments
 (0)