Skip to content

Commit

Permalink
Add timestamps to show_all output in recognize_google_cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
Uberi committed Dec 5, 2017
1 parent 6d0adb6 commit 6f61f6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/threaded_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def recognize_worker():

audio_queue.task_done() # mark the audio processing job as completed in the queue


# start a new thread to recognize audio, while this thread focuses on listening
recognize_thread = Thread(target=recognize_worker)
recognize_thread.daemon = True
Expand Down
9 changes: 5 additions & 4 deletions speech_recognition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,10 +962,11 @@ def recognize_google_cloud(self, audio_data, credentials_json=None, language="en
except ImportError:
raise RequestError("missing google-api-python-client module: ensure that google-api-python-client is set up correctly.")

if preferred_phrases is None:
speech_config = {"encoding": "FLAC", "sampleRateHertz": audio_data.sample_rate, "languageCode": language}
else:
speech_config = {"encoding": "FLAC", "sampleRateHertz": audio_data.sample_rate, "languageCode": language, "speechContext": {"phrases": preferred_phrases}}
speech_config = {"encoding": "FLAC", "sampleRateHertz": audio_data.sample_rate, "languageCode": language}
if preferred_phrases is not None:
speech_config["speechContext"] = {"phrases": preferred_phrases}
if show_all:
speech_config["enableWordTimeOffsets"] = True # some useful extra options for when we want all the output
request = speech_service.speech().recognize(body={"audio": {"content": base64.b64encode(flac_data).decode("utf8")}, "config": speech_config})

try:
Expand Down

0 comments on commit 6f61f6b

Please sign in to comment.