File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -179,12 +179,13 @@ def request_stream(data_stream, rate):
179
179
def listen_print_loop (recognize_stream ):
180
180
global _index
181
181
global _results
182
- update_search = True
183
- say_update = False
184
182
for resp in recognize_stream :
185
183
if resp .error .code != code_pb2 .OK :
186
184
raise RuntimeError ('Server error: ' + resp .error .message )
187
185
186
+ update_search = True
187
+ say_update = False
188
+
188
189
# Exit recognition if any of the transcribed phrases could be
189
190
# one of our keywords.
190
191
if any (re .search (r'\b(exit|quit)\b' , alt .transcript , re .I )
@@ -198,18 +199,19 @@ def listen_print_loop(recognize_stream):
198
199
if any (re .search (r'\b(next)\b' , alt .transcript , re .I )
199
200
for result in resp .results
200
201
for alt in result .alternatives ):
202
+ print ('>>> Next result' )
201
203
update_search = False
202
204
say_update = True
203
205
_index = _index + 1
204
- break
205
206
206
207
# Retrieve search results using speech result
207
208
if update_search and resp .results :
208
209
for result in resp .results :
209
210
print ('Searching for ' + result .alternatives [0 ].transcript )
210
211
google_search (result .alternatives [0 ].transcript , num = 10 )
211
- say_update = True
212
- _index = 0
212
+ if len (result .alternatives ) > 0 :
213
+ say_update = True
214
+ _index = 0
213
215
214
216
if say_update and _index < len (_results ):
215
217
print ('Saying: ' + _results [_index ]['snippet' ])
You can’t perform that action at this time.
0 commit comments