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

add immediate option for cloudspeech recognize #234

Merged
merged 2 commits into from
Jan 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add documentation for immediate above, eg:

Args:
    immediate: ignore the hotword list, even if it has been populated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I place the example in the function documentation too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, hopefully people who need it can find it there :)

if immediate:
return text
elif self._hotwords and text:
text = text.lower()
loc_min = len(text)
hotword_found = ''
Expand Down