Skip to content

Commit 50d0980

Browse files
committed
Splits source files into text and audio queries
Bug: 78773302 Change-Id: I14d4b1bc71a2578f484bd29edf5c2af8c2d36791
1 parent 5f70c1c commit 50d0980

File tree

8 files changed

+292
-49
lines changed

8 files changed

+292
-49
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ client_secret.json
77
credentials.json
88
# Do not commit binaries
99
googleapis.ar
10-
run_assistant
10+
run_assistant_audio
11+
run_assistant_text
1112
# Generated files
1213
src/embedded_assistant*

Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,26 @@ CXXFLAGS += $(ALSA_CFLAGS)
7575
LDFLAGS += $(ALSA_LDFLAGS)
7676
endif
7777

78+
ASSISTANT_O = $(AUDIO_SRCS:.cc=.o) ./src/audio_input_file.o ./src/json_util.o \
79+
./src/run_assistant_audio.o ./src/run_assistant_text.o
80+
ASSISTANT_AUDIO_O = $(AUDIO_SRCS:.cc=.o) ./src/audio_input_file.o ./src/json_util.o \
81+
./src/run_assistant_audio.o
82+
ASSISTANT_TEXT_O = ./src/json_util.o ./src/run_assistant_text.o
83+
7884
.PHONY: all
7985
all: run_assistant
8086

8187
googleapis.ar: $(GOOGLEAPIS_CCS:.cc=.o)
8288
$(AR) r $@ $?
8389

84-
run_assistant.o: $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.h)
90+
run_assistant: run_assistant_audio run_assistant_text
91+
92+
run_assistant_audio: $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.o) googleapis.ar \
93+
$(ASSISTANT_AUDIO_O)
94+
$(CXX) $^ $(LDFLAGS) -o $@
8595

86-
run_assistant: $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.o) googleapis.ar \
87-
$(AUDIO_SRCS:.cc=.o) ./src/audio_input_file.o ./src/json_util.o ./src/run_assistant.o
96+
run_assistant_text: $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.o) googleapis.ar \
97+
$(ASSISTANT_TEXT_O)
8898
$(CXX) $^ $(LDFLAGS) -o $@
8999

90100
json_util_test: ./src/json_util.o ./src/json_util_test.o
@@ -102,8 +112,8 @@ protobufs: $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.h) $(GOOGLEAPIS_ASSISTANT_CCS)
102112

103113
.PHONY: clean
104114
clean:
105-
rm -f *.o run_assistant googleapis.ar \
115+
rm -f run_assistant_audio run_assistant_text googleapis.ar \
106116
$(GOOGLEAPIS_CCS:.cc=.o) \
107117
$(GOOGLEAPIS_ASSISTANT_CCS) $(GOOGLEAPIS_ASSISTANT_CCS:.cc=.h) \
108118
$(GOOGLEAPIS_ASSISTANT_CCS:.cc=.o) \
109-
./src/*.o
119+
$(ASSISTANT_O)

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,34 @@ make run_assistant
8282
* Move it in this folder and rename it to `client_secret.json`
8383
* run `get_credentials.sh` in this folder. It will create the file `credentials.json`.
8484

85-
7. Start `run_assistant`
86-
```
87-
./run_assistant --audio_input ./resources/weather_in_mountain_view.raw --credentials_file ./credentials.json
85+
7. Start one of the `run_assistant` samples
86+
87+
```bash
88+
./run_assistant_audio --audio_input ./resources/weather_in_mountain_view.raw --credentials_file ./credentials.json
8889
```
8990

9091
On a Linux workstation, you can alternatively use ALSA for audio input:
91-
```
92-
./run_assistant --audio_input ALSA_INPUT --credentials_file ./credentials.json
92+
93+
```bash
94+
./run_assistant_audio --audio_input ALSA_INPUT --credentials_file ./credentials.json
9395
```
9496

9597
You can use a text-based query instead of audio. This allows you to continually enter text queries to the Assistant.
96-
```
97-
./run_assistant --text_input --credentials_file ./credentials.json --credentials_type USER_ACCOUNT
98+
99+
```bash
100+
./run_assistant_text --credentials_file ./credentials.json
98101
```
99102

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

102-
```
103-
echo "what time is it" | ./run_assistant --text_input --credentials_file ./credentials.json --credentials_type USER_ACCOUNT
105+
```bash
106+
echo "what time is it" | ./run_assistant_text --credentials_file ./credentials.json
104107
```
105108

106109
To change the locale, include a `locale` parameter:
107110

108-
```
109-
echo "Bonjour" | ./run_assistant --text_input --credentials_file ./credentials.json --credentials_type USER_ACCOUNT --locale "fr-FR"
111+
```bash
112+
echo "Bonjour" | ./run_assistant_text --credentials_file ./credentials.json --locale "fr-FR"
110113
```
111114

112115
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.
Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ std::shared_ptr<Channel> CreateChannel(const std::string& host) {
8686
}
8787

8888
void PrintUsage() {
89-
std::cerr << "Usage: ./run_assistant "
90-
<< "[--audio_input [<" << kALSAAudioInput << ">|<audio_file>] OR --text_input] "
89+
std::cerr << "Usage: ./run_assistant_audio "
90+
<< "--audio_input [<" << kALSAAudioInput << ">|<audio_file>] "
9191
<< "--credentials_file <credentials_file> "
9292
<< "[--credentials_type <" << kCredentialsTypeUserAccount << ">] "
9393
<< "[--api_endpoint <API endpoint>] "
@@ -101,7 +101,6 @@ bool GetCommandLineFlags(
101101
std::string* locale) {
102102
const struct option long_options[] = {
103103
{"audio_input", required_argument, nullptr, 'a'},
104-
{"text_input", no_argument, nullptr, 't'},
105104
{"credentials_file", required_argument, nullptr, 'f'},
106105
{"credentials_type", required_argument, nullptr, 'c'},
107106
{"api_endpoint", required_argument, nullptr, 'e'},
@@ -113,17 +112,14 @@ bool GetCommandLineFlags(
113112
while (true) {
114113
int option_index;
115114
int option_char =
116-
getopt_long(argc, argv, "a:t:f:c:e:l:v", long_options, &option_index);
115+
getopt_long(argc, argv, "a:f:c:e:l:v", long_options, &option_index);
117116
if (option_char == -1) {
118117
break;
119118
}
120119
switch (option_char) {
121120
case 'a':
122121
*audio_input = optarg;
123122
break;
124-
case 't':
125-
use_text = true;
126-
break;
127123
case 'f':
128124
*credentials_file_path = optarg;
129125
break;
@@ -154,7 +150,7 @@ bool GetCommandLineFlags(
154150
}
155151

156152
int main(int argc, char** argv) {
157-
std::string audio_input_source, text_input_source, credentials_file_path, credentials_type,
153+
std::string audio_input_source, credentials_file_path, credentials_type,
158154
api_endpoint, locale;
159155
// Initialize gRPC and DNS resolvers
160156
// https://github.com/grpc/grpc/issues/11366#issuecomment-328595941
@@ -169,19 +165,6 @@ int main(int argc, char** argv) {
169165
}
170166

171167
while (true) {
172-
if (use_text) {
173-
// Take in any text
174-
std::clog << ": " << std::endl;
175-
std::getline(std::cin, text_input_source);
176-
// Take in any text
177-
if (text_input_source.empty()) {
178-
// Input is empty. This can happen if the user entered
179-
// no text or if the input source is through a terminal
180-
// pipe. In either case, this will be interpreted as
181-
// an exit condition.
182-
return 0;
183-
}
184-
}
185168
// Create an AssistRequest
186169
AssistRequest request;
187170
auto* assist_config = request.mutable_config();
@@ -210,10 +193,8 @@ int main(int argc, char** argv) {
210193
assist_config->mutable_audio_in_config()->set_encoding(
211194
AudioInConfig::LINEAR16);
212195
assist_config->mutable_audio_in_config()->set_sample_rate_hertz(16000);
213-
} else if (!text_input_source.empty()) {
214-
assist_config->set_text_query(text_input_source);
215196
} else {
216-
std::cerr << "requires either --audio_input or --text_input" << std::endl;
197+
std::cerr << "requires --audio_input" << std::endl;
217198
return -1;
218199
}
219200

@@ -344,7 +325,7 @@ int main(int argc, char** argv) {
344325
return -1;
345326
}
346327

347-
if (!use_text && audio_input_source != kALSAAudioInput) {
328+
if (audio_input_source != kALSAAudioInput) {
348329
// A filepath was used as the audio input to this program
349330
// If this is the case, then we can stop the program after
350331
// one turn.

0 commit comments

Comments
 (0)