diff --git a/src/aiy/cloudspeech.py b/src/aiy/cloudspeech.py index 184ed9b5..160fa63f 100644 --- a/src/aiy/cloudspeech.py +++ b/src/aiy/cloudspeech.py @@ -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 = ''