Skip to content

Commit 9a56b9b

Browse files
committed
Stops repeating the first result
1 parent ff878d3 commit 9a56b9b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

speech/speech-to-search/speech_to_search.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,13 @@ def request_stream(data_stream, rate):
179179
def listen_print_loop(recognize_stream):
180180
global _index
181181
global _results
182-
update_search = True
183-
say_update = False
184182
for resp in recognize_stream:
185183
if resp.error.code != code_pb2.OK:
186184
raise RuntimeError('Server error: ' + resp.error.message)
187185

186+
update_search = True
187+
say_update = False
188+
188189
# Exit recognition if any of the transcribed phrases could be
189190
# one of our keywords.
190191
if any(re.search(r'\b(exit|quit)\b', alt.transcript, re.I)
@@ -198,18 +199,19 @@ def listen_print_loop(recognize_stream):
198199
if any(re.search(r'\b(next)\b', alt.transcript, re.I)
199200
for result in resp.results
200201
for alt in result.alternatives):
202+
print('>>> Next result')
201203
update_search = False
202204
say_update = True
203205
_index = _index + 1
204-
break
205206

206207
# Retrieve search results using speech result
207208
if update_search and resp.results:
208209
for result in resp.results:
209210
print('Searching for ' + result.alternatives[0].transcript)
210211
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
213215

214216
if say_update and _index < len(_results):
215217
print('Saying: ' + _results[_index]['snippet'])

0 commit comments

Comments
 (0)