Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Commit

Permalink
add immediate option for cloudspeech recognize (#234)
Browse files Browse the repository at this point in the history
* add immediate option for cloudspeech recognize

* add documentation for immediate argument
  • Loading branch information
rkkautsar authored and drigz committed Jan 4, 2018
1 parent 4580917 commit 2c808d8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/aiy/cloudspeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,30 @@ def __init__(self, credentials_file):
self._recorder = aiy.audio.get_recorder()
self._hotwords = []

def recognize(self):
def recognize(self, immediate=False):
"""Recognizes the user's speech and transcript it into text.
This function listens to the user's speech via the VoiceHat speaker. Then it
contacts Google CloudSpeech APIs and returns a textual transcript if possible.
If hotword list is populated this method will only respond if hotword is said.
Args:
immediate: ignore the hotword list, even if it has been populated
may be used to create a conversational experience, for example:
text = recognizer.recognize()
if 'call a friend' in text:
aiy.audio.say('OK, which one?')
friend = recognizer.recognize(immediate=True)
make_a_call(friend)
"""
self._request.reset()
self._request.set_endpointer_cb(self._endpointer_callback)
self._recorder.add_processor(self._request)
text = self._request.do_request().transcript
if self._hotwords and text:
if immediate:
return text
elif self._hotwords and text:
text = text.lower()
loc_min = len(text)
hotword_found = ''
Expand Down

0 comments on commit 2c808d8

Please sign in to comment.