From aa0de9412a71e09a02e7529e570bf9c90585f519 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 13 Jun 2017 12:23:01 -0700 Subject: [PATCH 01/29] Migrate quickstart to GAPIC client library --- speech/cloud-client/quickstart.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py index 81966cf8d336..b65507d02dc3 100644 --- a/speech/cloud-client/quickstart.py +++ b/speech/cloud-client/quickstart.py @@ -21,10 +21,12 @@ def run_quickstart(): import os # Imports the Google Cloud client library - from google.cloud import speech + from google.cloud.gapic.speech.v1 import speech_client + from google.cloud.gapic.speech.v1 import enums + from google.cloud.proto.speech.v1 import cloud_speech_pb2 # Instantiates a client - speech_client = speech.Client() + client = speech_client.SpeechClient() # The name of the audio file to transcribe file_name = os.path.join( @@ -35,14 +37,19 @@ def run_quickstart(): # Loads the audio into memory with io.open(file_name, 'rb') as audio_file: content = audio_file.read() - sample = speech_client.sample( - content, - source_uri=None, - encoding='LINEAR16', - sample_rate_hertz=16000) + audio = cloud_speech_pb2.RecognitionAudio(content=content) + + encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 + sample_rate_hertz = 16000 + language_code = 'en-US' + config = cloud_speech_pb2.RecognitionConfig( + encoding=encoding, + sample_rate_hertz=sample_rate_hertz, + language_code=language_code) # Detects speech in the audio file - alternatives = sample.recognize('en-US') + response = client.recognize(config, audio) + alternatives = response.results[0].alternatives for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) From c695c82a1b9a9e33e13dfa911c397a04051cd836 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 13 Jun 2017 15:33:59 -0700 Subject: [PATCH 02/29] Migrate transcribe to GAPIC client library --- speech/cloud-client/transcribe.py | 47 ++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/speech/cloud-client/transcribe.py b/speech/cloud-client/transcribe.py index 7c138ec963a4..1b1398a7e179 100644 --- a/speech/cloud-client/transcribe.py +++ b/speech/cloud-client/transcribe.py @@ -30,34 +30,49 @@ def transcribe_file(speech_file): """Transcribe the given audio file.""" - from google.cloud import speech - speech_client = speech.Client() + from google.cloud.gapic.speech.v1 import speech_client + from google.cloud.gapic.speech.v1 import enums + from google.cloud.proto.speech.v1 import cloud_speech_pb2 + client = speech_client.SpeechClient() with io.open(speech_file, 'rb') as audio_file: content = audio_file.read() - audio_sample = speech_client.sample( - content=content, - source_uri=None, - encoding='LINEAR16', - sample_rate_hertz=16000) + audio = cloud_speech_pb2.RecognitionAudio(content=content) + + encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 + sample_rate_hertz = 16000 + language_code = 'en-US' + config = cloud_speech_pb2.RecognitionConfig( + encoding=encoding, + sample_rate_hertz=sample_rate_hertz, + language_code=language_code) + + response = client.recognize(config, audio) + alternatives = response.results[0].alternatives - alternatives = audio_sample.recognize('en-US') for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) def transcribe_gcs(gcs_uri): """Transcribes the audio file specified by the gcs_uri.""" - from google.cloud import speech - speech_client = speech.Client() + from google.cloud.gapic.speech.v1 import speech_client + from google.cloud.gapic.speech.v1 import enums + from google.cloud.proto.speech.v1 import cloud_speech_pb2 + client = speech_client.SpeechClient() + audio = cloud_speech_pb2.RecognitionAudio(uri=gcs_uri) + + encoding = enums.RecognitionConfig.AudioEncoding.FLAC + sample_rate_hertz = 16000 + language_code = 'en-US' + config = cloud_speech_pb2.RecognitionConfig( + encoding=encoding, + sample_rate_hertz=sample_rate_hertz, + language_code=language_code) - audio_sample = speech_client.sample( - content=None, - source_uri=gcs_uri, - encoding='FLAC', - sample_rate_hertz=16000) + response = client.recognize(config, audio) + alternatives = response.results[0].alternatives - alternatives = audio_sample.recognize('en-US') for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) From 4777dc60b8a4c7b2912696f1b980c63d8ea339e9 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 13 Jun 2017 17:09:09 -0700 Subject: [PATCH 03/29] Migrate transcribe_async to GAPIC client library --- speech/cloud-client/transcribe_async.py | 61 ++++++++++++++----------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index fd0a0340b1c4..ff5b43d5cabd 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -29,30 +29,35 @@ def transcribe_file(speech_file): """Transcribe the given audio file asynchronously.""" - from google.cloud import speech - speech_client = speech.Client() + from google.cloud.gapic.speech.v1 import speech_client + from google.cloud.gapic.speech.v1 import enums + from google.cloud.proto.speech.v1 import cloud_speech_pb2 + client = speech_client.SpeechClient() with io.open(speech_file, 'rb') as audio_file: content = audio_file.read() - audio_sample = speech_client.sample( - content, - source_uri=None, - encoding='LINEAR16', - sample_rate_hertz=16000) + audio = cloud_speech_pb2.RecognitionAudio(content=content) - operation = audio_sample.long_running_recognize('en-US') + encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 + sample_rate_hertz = 16000 + language_code = 'en-US' + config = cloud_speech_pb2.RecognitionConfig( + encoding=encoding, + sample_rate_hertz=sample_rate_hertz, + language_code=language_code) + + operation = client.long_running_recognize(config, audio) retry_count = 100 - while retry_count > 0 and not operation.complete: + while retry_count > 0 and not operation.done(): retry_count -= 1 time.sleep(2) - operation.poll() - if not operation.complete: + if not operation.done(): print('Operation not complete and retry limit reached.') return - alternatives = operation.results + alternatives = operation.result().results[0].alternatives for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) print('Confidence: {}'.format(alternative.confidence)) @@ -61,28 +66,32 @@ def transcribe_file(speech_file): def transcribe_gcs(gcs_uri): """Asynchronously transcribes the audio file specified by the gcs_uri.""" - from google.cloud import speech - speech_client = speech.Client() - - audio_sample = speech_client.sample( - content=None, - source_uri=gcs_uri, - encoding='FLAC', - sample_rate_hertz=16000) - - operation = audio_sample.long_running_recognize('en-US') + from google.cloud.gapic.speech.v1 import speech_client + from google.cloud.gapic.speech.v1 import enums + from google.cloud.proto.speech.v1 import cloud_speech_pb2 + client = speech_client.SpeechClient() + audio = cloud_speech_pb2.RecognitionAudio(uri=gcs_uri) + + encoding = enums.RecognitionConfig.AudioEncoding.FLAC + sample_rate_hertz = 16000 + language_code = 'en-US' + config = cloud_speech_pb2.RecognitionConfig( + encoding=encoding, + sample_rate_hertz=sample_rate_hertz, + language_code=language_code) + + operation = client.long_running_recognize(config, audio) retry_count = 100 - while retry_count > 0 and not operation.complete: + while retry_count > 0 and not operation.done(): retry_count -= 1 time.sleep(2) - operation.poll() - if not operation.complete: + if not operation.done(): print('Operation not complete and retry limit reached.') return - alternatives = operation.results + alternatives = operation.result().results[0].alternatives for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) print('Confidence: {}'.format(alternative.confidence)) From e77f5f8652ee0a850a2fa9d3a3798198de5ab875 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 14 Jun 2017 12:13:47 -0700 Subject: [PATCH 04/29] Migrate transcribe_streaming to GAPIC client library --- speech/cloud-client/transcribe_streaming.py | 42 ++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 429db7910452..074c21219afc 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -28,24 +28,40 @@ def transcribe_streaming(stream_file): """Streams transcription of the given audio file.""" - from google.cloud import speech - speech_client = speech.Client() + from google.cloud.gapic.speech.v1 import speech_client + from google.cloud.gapic.speech.v1 import enums + from google.cloud.proto.speech.v1 import cloud_speech_pb2 + client = speech_client.SpeechClient() with io.open(stream_file, 'rb') as audio_file: - audio_sample = speech_client.sample( - stream=audio_file, - encoding=speech.encoding.Encoding.LINEAR16, - sample_rate_hertz=16000) - alternatives = audio_sample.streaming_recognize('en-US') + content = audio_file.read() + audio = cloud_speech_pb2.RecognitionAudio(content=content) + content_request = cloud_speech_pb2.StreamingRecognizeRequest(audio_content=content) - for alternative in alternatives: - print('Finished: {}'.format(alternative.is_final)) - print('Stability: {}'.format(alternative.stability)) - print('Confidence: {}'.format(alternative.confidence)) - print('Transcript: {}'.format(alternative.transcript)) + encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 + sample_rate_hertz = 16000 + language_code = 'en-US' + config = cloud_speech_pb2.RecognitionConfig( + encoding=encoding, + sample_rate_hertz=sample_rate_hertz, + language_code=language_code) + streaming_config = cloud_speech_pb2.StreamingRecognitionConfig(config=config) + config_request = cloud_speech_pb2.StreamingRecognizeRequest(streaming_config=streaming_config) -if __name__ == '__main__': + requests = (r for r in [config_request, content_request]) + + for response in client.streaming_recognize(requests): + for result in response.results: + print('Finished: {}'.format(result.is_final)) + print('Stability: {}'.format(result.stability)) + alternatives = result.alternatives + for alternative in alternatives: + print('Confidence: {}'.format(alternative.confidence)) + print('Transcript: {}'.format(alternative.transcript)) + + +if __name__ == '__main__' and False: parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) From 199a7482a163428dca73cdde7210fbd8c56d34ab Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Mon, 19 Jun 2017 17:04:29 -0700 Subject: [PATCH 05/29] clean up --- speech/cloud-client/transcribe_async.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index ff5b43d5cabd..5306ddbf827d 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -61,7 +61,6 @@ def transcribe_file(speech_file): for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) print('Confidence: {}'.format(alternative.confidence)) - # [END send_request] def transcribe_gcs(gcs_uri): @@ -95,7 +94,6 @@ def transcribe_gcs(gcs_uri): for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) print('Confidence: {}'.format(alternative.confidence)) - # [END send_request_gcs] if __name__ == '__main__': From 51c4d01f5456cc58bb3f7cf5efc61a7bbfaabd0e Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 21 Jun 2017 09:38:04 -0700 Subject: [PATCH 06/29] clean up --- speech/cloud-client/transcribe_streaming.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 074c21219afc..58c5aa5e780a 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -61,7 +61,7 @@ def transcribe_streaming(stream_file): print('Transcript: {}'.format(alternative.transcript)) -if __name__ == '__main__' and False: +if __name__ == '__main__': parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) From 0de6c7c6cebd2fd32ec0f7463c16b5d1bd0811d7 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Mon, 26 Jun 2017 16:30:59 -0700 Subject: [PATCH 07/29] Import from google.cloud.speech --- speech/cloud-client/quickstart.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py index b65507d02dc3..b80bd3620422 100644 --- a/speech/cloud-client/quickstart.py +++ b/speech/cloud-client/quickstart.py @@ -21,12 +21,12 @@ def run_quickstart(): import os # Imports the Google Cloud client library - from google.cloud.gapic.speech.v1 import speech_client - from google.cloud.gapic.speech.v1 import enums - from google.cloud.proto.speech.v1 import cloud_speech_pb2 + from google.cloud.speech import SpeechClient + from google.cloud.speech import enums + from google.cloud.speech import types # Instantiates a client - client = speech_client.SpeechClient() + client = SpeechClient() # The name of the audio file to transcribe file_name = os.path.join( @@ -37,12 +37,12 @@ def run_quickstart(): # Loads the audio into memory with io.open(file_name, 'rb') as audio_file: content = audio_file.read() - audio = cloud_speech_pb2.RecognitionAudio(content=content) + audio = types.RecognitionAudio(content=content) encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 sample_rate_hertz = 16000 language_code = 'en-US' - config = cloud_speech_pb2.RecognitionConfig( + config = types.RecognitionConfig( encoding=encoding, sample_rate_hertz=sample_rate_hertz, language_code=language_code) From a594c7013afd1137a53f37a2dfab461a6b1b91d4 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Mon, 26 Jun 2017 17:04:14 -0700 Subject: [PATCH 08/29] update transcribe samples --- speech/cloud-client/transcribe.py | 24 ++++++++++----------- speech/cloud-client/transcribe_async.py | 24 ++++++++++----------- speech/cloud-client/transcribe_streaming.py | 21 +++++++++--------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/speech/cloud-client/transcribe.py b/speech/cloud-client/transcribe.py index 1b1398a7e179..0cfdf39cffb0 100644 --- a/speech/cloud-client/transcribe.py +++ b/speech/cloud-client/transcribe.py @@ -30,19 +30,19 @@ def transcribe_file(speech_file): """Transcribe the given audio file.""" - from google.cloud.gapic.speech.v1 import speech_client - from google.cloud.gapic.speech.v1 import enums - from google.cloud.proto.speech.v1 import cloud_speech_pb2 - client = speech_client.SpeechClient() + from google.cloud.speech import SpeechClient + from google.cloud.speech import enums + from google.cloud.speech import types + client = SpeechClient() with io.open(speech_file, 'rb') as audio_file: content = audio_file.read() - audio = cloud_speech_pb2.RecognitionAudio(content=content) + audio = types.RecognitionAudio(content=content) encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 sample_rate_hertz = 16000 language_code = 'en-US' - config = cloud_speech_pb2.RecognitionConfig( + config = types.RecognitionConfig( encoding=encoding, sample_rate_hertz=sample_rate_hertz, language_code=language_code) @@ -56,16 +56,16 @@ def transcribe_file(speech_file): def transcribe_gcs(gcs_uri): """Transcribes the audio file specified by the gcs_uri.""" - from google.cloud.gapic.speech.v1 import speech_client - from google.cloud.gapic.speech.v1 import enums - from google.cloud.proto.speech.v1 import cloud_speech_pb2 - client = speech_client.SpeechClient() - audio = cloud_speech_pb2.RecognitionAudio(uri=gcs_uri) + from google.cloud.speech import SpeechClient + from google.cloud.speech import enums + from google.cloud.speech import types + client = SpeechClient() + audio = types.RecognitionAudio(uri=gcs_uri) encoding = enums.RecognitionConfig.AudioEncoding.FLAC sample_rate_hertz = 16000 language_code = 'en-US' - config = cloud_speech_pb2.RecognitionConfig( + config = types.RecognitionConfig( encoding=encoding, sample_rate_hertz=sample_rate_hertz, language_code=language_code) diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index 5306ddbf827d..81a858eab1c0 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -29,19 +29,19 @@ def transcribe_file(speech_file): """Transcribe the given audio file asynchronously.""" - from google.cloud.gapic.speech.v1 import speech_client - from google.cloud.gapic.speech.v1 import enums - from google.cloud.proto.speech.v1 import cloud_speech_pb2 - client = speech_client.SpeechClient() + from google.cloud.speech import SpeechClient + from google.cloud.speech import enums + from google.cloud.speech import types + client = SpeechClient() with io.open(speech_file, 'rb') as audio_file: content = audio_file.read() - audio = cloud_speech_pb2.RecognitionAudio(content=content) + audio = types.RecognitionAudio(content=content) encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 sample_rate_hertz = 16000 language_code = 'en-US' - config = cloud_speech_pb2.RecognitionConfig( + config = types.RecognitionConfig( encoding=encoding, sample_rate_hertz=sample_rate_hertz, language_code=language_code) @@ -65,16 +65,16 @@ def transcribe_file(speech_file): def transcribe_gcs(gcs_uri): """Asynchronously transcribes the audio file specified by the gcs_uri.""" - from google.cloud.gapic.speech.v1 import speech_client - from google.cloud.gapic.speech.v1 import enums - from google.cloud.proto.speech.v1 import cloud_speech_pb2 - client = speech_client.SpeechClient() - audio = cloud_speech_pb2.RecognitionAudio(uri=gcs_uri) + from google.cloud.speech import SpeechClient + from google.cloud.speech import enums + from google.cloud.speech import types + client = SpeechClient() + audio = types.RecognitionAudio(uri=gcs_uri) encoding = enums.RecognitionConfig.AudioEncoding.FLAC sample_rate_hertz = 16000 language_code = 'en-US' - config = cloud_speech_pb2.RecognitionConfig( + config = types.RecognitionConfig( encoding=encoding, sample_rate_hertz=sample_rate_hertz, language_code=language_code) diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 58c5aa5e780a..701c2df73e83 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -28,30 +28,29 @@ def transcribe_streaming(stream_file): """Streams transcription of the given audio file.""" - from google.cloud.gapic.speech.v1 import speech_client - from google.cloud.gapic.speech.v1 import enums - from google.cloud.proto.speech.v1 import cloud_speech_pb2 - client = speech_client.SpeechClient() + from google.cloud.speech import SpeechClient + from google.cloud.speech import enums + from google.cloud.speech import types + client = SpeechClient() with io.open(stream_file, 'rb') as audio_file: content = audio_file.read() - audio = cloud_speech_pb2.RecognitionAudio(content=content) - content_request = cloud_speech_pb2.StreamingRecognizeRequest(audio_content=content) + audio = types.RecognitionAudio(content=content) + request = types.StreamingRecognizeRequest(audio_content=content) encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 sample_rate_hertz = 16000 language_code = 'en-US' - config = cloud_speech_pb2.RecognitionConfig( + config = types.RecognitionConfig( encoding=encoding, sample_rate_hertz=sample_rate_hertz, language_code=language_code) - streaming_config = cloud_speech_pb2.StreamingRecognitionConfig(config=config) - config_request = cloud_speech_pb2.StreamingRecognizeRequest(streaming_config=streaming_config) + config = types.StreamingRecognitionConfig(config=config) - requests = (r for r in [config_request, content_request]) + requests = [request] - for response in client.streaming_recognize(requests): + for response in client.streaming_recognize(config, requests): for result in response.results: print('Finished: {}'.format(result.is_final)) print('Stability: {}'.format(result.stability)) From 9129caf0dc44e3eaf81d6ee380aebb839fa50dde Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Mon, 26 Jun 2017 17:07:59 -0700 Subject: [PATCH 09/29] import in alphabetic order --- speech/cloud-client/quickstart.py | 2 +- speech/cloud-client/transcribe.py | 4 ++-- speech/cloud-client/transcribe_async.py | 4 ++-- speech/cloud-client/transcribe_streaming.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py index b80bd3620422..706a46fd0d2a 100644 --- a/speech/cloud-client/quickstart.py +++ b/speech/cloud-client/quickstart.py @@ -21,8 +21,8 @@ def run_quickstart(): import os # Imports the Google Cloud client library - from google.cloud.speech import SpeechClient from google.cloud.speech import enums + from google.cloud.speech import SpeechClient from google.cloud.speech import types # Instantiates a client diff --git a/speech/cloud-client/transcribe.py b/speech/cloud-client/transcribe.py index 0cfdf39cffb0..a677ecfbeea8 100644 --- a/speech/cloud-client/transcribe.py +++ b/speech/cloud-client/transcribe.py @@ -30,8 +30,8 @@ def transcribe_file(speech_file): """Transcribe the given audio file.""" - from google.cloud.speech import SpeechClient from google.cloud.speech import enums + from google.cloud.speech import SpeechClient from google.cloud.speech import types client = SpeechClient() @@ -56,8 +56,8 @@ def transcribe_file(speech_file): def transcribe_gcs(gcs_uri): """Transcribes the audio file specified by the gcs_uri.""" - from google.cloud.speech import SpeechClient from google.cloud.speech import enums + from google.cloud.speech import SpeechClient from google.cloud.speech import types client = SpeechClient() audio = types.RecognitionAudio(uri=gcs_uri) diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index 81a858eab1c0..cdca815262bb 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -29,8 +29,8 @@ def transcribe_file(speech_file): """Transcribe the given audio file asynchronously.""" - from google.cloud.speech import SpeechClient from google.cloud.speech import enums + from google.cloud.speech import SpeechClient from google.cloud.speech import types client = SpeechClient() @@ -65,8 +65,8 @@ def transcribe_file(speech_file): def transcribe_gcs(gcs_uri): """Asynchronously transcribes the audio file specified by the gcs_uri.""" - from google.cloud.speech import SpeechClient from google.cloud.speech import enums + from google.cloud.speech import SpeechClient from google.cloud.speech import types client = SpeechClient() audio = types.RecognitionAudio(uri=gcs_uri) diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 701c2df73e83..1a0b38fecb74 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -28,8 +28,8 @@ def transcribe_streaming(stream_file): """Streams transcription of the given audio file.""" - from google.cloud.speech import SpeechClient from google.cloud.speech import enums + from google.cloud.speech import SpeechClient from google.cloud.speech import types client = SpeechClient() From 4db0f4552e5c2dc535d97ca66ac495418660bf15 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 29 Jun 2017 09:24:05 -0700 Subject: [PATCH 10/29] remove unused variable --- speech/cloud-client/transcribe_streaming.py | 1 - 1 file changed, 1 deletion(-) diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 1a0b38fecb74..f0a022ae965e 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -35,7 +35,6 @@ def transcribe_streaming(stream_file): with io.open(stream_file, 'rb') as audio_file: content = audio_file.read() - audio = types.RecognitionAudio(content=content) request = types.StreamingRecognizeRequest(audio_content=content) encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 From f09dfec9b2e36e8c5748857ca4c9d60928b04696 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 29 Jun 2017 15:49:24 -0700 Subject: [PATCH 11/29] use strings instead of enums --- speech/cloud-client/quickstart.py | 3 +-- speech/cloud-client/transcribe.py | 6 ++---- speech/cloud-client/transcribe_async.py | 6 ++---- speech/cloud-client/transcribe_streaming.py | 3 +-- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py index 706a46fd0d2a..b387f5e966d2 100644 --- a/speech/cloud-client/quickstart.py +++ b/speech/cloud-client/quickstart.py @@ -21,7 +21,6 @@ def run_quickstart(): import os # Imports the Google Cloud client library - from google.cloud.speech import enums from google.cloud.speech import SpeechClient from google.cloud.speech import types @@ -39,7 +38,7 @@ def run_quickstart(): content = audio_file.read() audio = types.RecognitionAudio(content=content) - encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 + encoding = 'LINEAR16' sample_rate_hertz = 16000 language_code = 'en-US' config = types.RecognitionConfig( diff --git a/speech/cloud-client/transcribe.py b/speech/cloud-client/transcribe.py index a677ecfbeea8..50603bb23613 100644 --- a/speech/cloud-client/transcribe.py +++ b/speech/cloud-client/transcribe.py @@ -30,7 +30,6 @@ def transcribe_file(speech_file): """Transcribe the given audio file.""" - from google.cloud.speech import enums from google.cloud.speech import SpeechClient from google.cloud.speech import types client = SpeechClient() @@ -39,7 +38,7 @@ def transcribe_file(speech_file): content = audio_file.read() audio = types.RecognitionAudio(content=content) - encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 + encoding = 'LINEAR16' sample_rate_hertz = 16000 language_code = 'en-US' config = types.RecognitionConfig( @@ -56,13 +55,12 @@ def transcribe_file(speech_file): def transcribe_gcs(gcs_uri): """Transcribes the audio file specified by the gcs_uri.""" - from google.cloud.speech import enums from google.cloud.speech import SpeechClient from google.cloud.speech import types client = SpeechClient() audio = types.RecognitionAudio(uri=gcs_uri) - encoding = enums.RecognitionConfig.AudioEncoding.FLAC + encoding = 'FLAC' sample_rate_hertz = 16000 language_code = 'en-US' config = types.RecognitionConfig( diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index cdca815262bb..69802276ed14 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -29,7 +29,6 @@ def transcribe_file(speech_file): """Transcribe the given audio file asynchronously.""" - from google.cloud.speech import enums from google.cloud.speech import SpeechClient from google.cloud.speech import types client = SpeechClient() @@ -38,7 +37,7 @@ def transcribe_file(speech_file): content = audio_file.read() audio = types.RecognitionAudio(content=content) - encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 + encoding = 'LINEAR16' sample_rate_hertz = 16000 language_code = 'en-US' config = types.RecognitionConfig( @@ -65,13 +64,12 @@ def transcribe_file(speech_file): def transcribe_gcs(gcs_uri): """Asynchronously transcribes the audio file specified by the gcs_uri.""" - from google.cloud.speech import enums from google.cloud.speech import SpeechClient from google.cloud.speech import types client = SpeechClient() audio = types.RecognitionAudio(uri=gcs_uri) - encoding = enums.RecognitionConfig.AudioEncoding.FLAC + encoding = 'FLAC' sample_rate_hertz = 16000 language_code = 'en-US' config = types.RecognitionConfig( diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index f0a022ae965e..8611cfbb647d 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -28,7 +28,6 @@ def transcribe_streaming(stream_file): """Streams transcription of the given audio file.""" - from google.cloud.speech import enums from google.cloud.speech import SpeechClient from google.cloud.speech import types client = SpeechClient() @@ -37,7 +36,7 @@ def transcribe_streaming(stream_file): content = audio_file.read() request = types.StreamingRecognizeRequest(audio_content=content) - encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16 + encoding = 'LINEAR16' sample_rate_hertz = 16000 language_code = 'en-US' config = types.RecognitionConfig( From 66d53aaaf7e69262241b41b82f5d056e573a145f Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 29 Jun 2017 17:06:13 -0700 Subject: [PATCH 12/29] restructure code --- speech/cloud-client/quickstart.py | 11 +++---- speech/cloud-client/transcribe.py | 20 ++++-------- speech/cloud-client/transcribe_async.py | 20 ++++-------- speech/cloud-client/transcribe_streaming.py | 36 +++++++++------------ 4 files changed, 34 insertions(+), 53 deletions(-) diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py index b387f5e966d2..57988ad77e8b 100644 --- a/speech/cloud-client/quickstart.py +++ b/speech/cloud-client/quickstart.py @@ -38,13 +38,10 @@ def run_quickstart(): content = audio_file.read() audio = types.RecognitionAudio(content=content) - encoding = 'LINEAR16' - sample_rate_hertz = 16000 - language_code = 'en-US' - config = types.RecognitionConfig( - encoding=encoding, - sample_rate_hertz=sample_rate_hertz, - language_code=language_code) + config = types.RecognitionConfig( + encoding='LINEAR16', + sample_rate_hertz=16000, + language_code='en-US') # Detects speech in the audio file response = client.recognize(config, audio) diff --git a/speech/cloud-client/transcribe.py b/speech/cloud-client/transcribe.py index 50603bb23613..e2c3ee57a35f 100644 --- a/speech/cloud-client/transcribe.py +++ b/speech/cloud-client/transcribe.py @@ -38,13 +38,10 @@ def transcribe_file(speech_file): content = audio_file.read() audio = types.RecognitionAudio(content=content) - encoding = 'LINEAR16' - sample_rate_hertz = 16000 - language_code = 'en-US' - config = types.RecognitionConfig( - encoding=encoding, - sample_rate_hertz=sample_rate_hertz, - language_code=language_code) + config = types.RecognitionConfig( + encoding='LINEAR16', + sample_rate_hertz=16000, + language_code='en-US') response = client.recognize(config, audio) alternatives = response.results[0].alternatives @@ -60,13 +57,10 @@ def transcribe_gcs(gcs_uri): client = SpeechClient() audio = types.RecognitionAudio(uri=gcs_uri) - encoding = 'FLAC' - sample_rate_hertz = 16000 - language_code = 'en-US' config = types.RecognitionConfig( - encoding=encoding, - sample_rate_hertz=sample_rate_hertz, - language_code=language_code) + encoding='FLAC', + sample_rate_hertz=16000, + language_code='en-US') response = client.recognize(config, audio) alternatives = response.results[0].alternatives diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index 69802276ed14..6dd7279665c7 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -37,13 +37,10 @@ def transcribe_file(speech_file): content = audio_file.read() audio = types.RecognitionAudio(content=content) - encoding = 'LINEAR16' - sample_rate_hertz = 16000 - language_code = 'en-US' - config = types.RecognitionConfig( - encoding=encoding, - sample_rate_hertz=sample_rate_hertz, - language_code=language_code) + config = types.RecognitionConfig( + encoding='LINEAR16', + sample_rate_hertz=16000, + language_code='en-US') operation = client.long_running_recognize(config, audio) @@ -69,13 +66,10 @@ def transcribe_gcs(gcs_uri): client = SpeechClient() audio = types.RecognitionAudio(uri=gcs_uri) - encoding = 'FLAC' - sample_rate_hertz = 16000 - language_code = 'en-US' config = types.RecognitionConfig( - encoding=encoding, - sample_rate_hertz=sample_rate_hertz, - language_code=language_code) + encoding='FLAC', + sample_rate_hertz=16000, + language_code='en-US') operation = client.long_running_recognize(config, audio) diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 8611cfbb647d..6a1be800b450 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -36,26 +36,22 @@ def transcribe_streaming(stream_file): content = audio_file.read() request = types.StreamingRecognizeRequest(audio_content=content) - encoding = 'LINEAR16' - sample_rate_hertz = 16000 - language_code = 'en-US' - config = types.RecognitionConfig( - encoding=encoding, - sample_rate_hertz=sample_rate_hertz, - language_code=language_code) - - config = types.StreamingRecognitionConfig(config=config) - - requests = [request] - - for response in client.streaming_recognize(config, requests): - for result in response.results: - print('Finished: {}'.format(result.is_final)) - print('Stability: {}'.format(result.stability)) - alternatives = result.alternatives - for alternative in alternatives: - print('Confidence: {}'.format(alternative.confidence)) - print('Transcript: {}'.format(alternative.transcript)) + config = types.RecognitionConfig( + encoding='LINEAR16', + sample_rate_hertz=16000, + language_code='en-US') + + requests = [request] + streaming_config = types.StreamingRecognitionConfig(config=config) + + for response in client.streaming_recognize(streaming_config, requests): + for result in response.results: + print('Finished: {}'.format(result.is_final)) + print('Stability: {}'.format(result.stability)) + alternatives = result.alternatives + for alternative in alternatives: + print('Confidence: {}'.format(alternative.confidence)) + print('Transcript: {}'.format(alternative.transcript)) if __name__ == '__main__': From 99b2e7969a6bc8d1658de9be2cc836fa62980df5 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 5 Jul 2017 08:54:36 -0700 Subject: [PATCH 13/29] comment on sreaming requests --- speech/cloud-client/transcribe_streaming.py | 1 + 1 file changed, 1 insertion(+) diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 6a1be800b450..fafb3b062b45 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -41,6 +41,7 @@ def transcribe_streaming(stream_file): sample_rate_hertz=16000, language_code='en-US') + # In practice requests should be a generator yielding chunks of audio data. requests = [request] streaming_config = types.StreamingRecognitionConfig(config=config) From c7d1ad73990f0552272611fd3806435eb6ec24ef Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 6 Jul 2017 10:33:24 -0700 Subject: [PATCH 14/29] import style --- speech/cloud-client/quickstart.py | 6 +++--- speech/cloud-client/transcribe.py | 9 +++++---- speech/cloud-client/transcribe_async.py | 9 +++++---- speech/cloud-client/transcribe_streaming.py | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py index 57988ad77e8b..4f3c31464a26 100644 --- a/speech/cloud-client/quickstart.py +++ b/speech/cloud-client/quickstart.py @@ -21,11 +21,11 @@ def run_quickstart(): import os # Imports the Google Cloud client library - from google.cloud.speech import SpeechClient + from google.cloud import speech from google.cloud.speech import types - + # Instantiates a client - client = SpeechClient() + client = speech.SpeechClient() # The name of the audio file to transcribe file_name = os.path.join( diff --git a/speech/cloud-client/transcribe.py b/speech/cloud-client/transcribe.py index e2c3ee57a35f..830e223bd5b1 100644 --- a/speech/cloud-client/transcribe.py +++ b/speech/cloud-client/transcribe.py @@ -30,9 +30,9 @@ def transcribe_file(speech_file): """Transcribe the given audio file.""" - from google.cloud.speech import SpeechClient + from google.cloud import speech from google.cloud.speech import types - client = SpeechClient() + client = speech.SpeechClient() with io.open(speech_file, 'rb') as audio_file: content = audio_file.read() @@ -52,9 +52,10 @@ def transcribe_file(speech_file): def transcribe_gcs(gcs_uri): """Transcribes the audio file specified by the gcs_uri.""" - from google.cloud.speech import SpeechClient + from google.cloud import speech from google.cloud.speech import types - client = SpeechClient() + client = speech.SpeechClient() + audio = types.RecognitionAudio(uri=gcs_uri) config = types.RecognitionConfig( diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index 6dd7279665c7..e40404c2ac8b 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -29,9 +29,9 @@ def transcribe_file(speech_file): """Transcribe the given audio file asynchronously.""" - from google.cloud.speech import SpeechClient + from google.cloud import speech from google.cloud.speech import types - client = SpeechClient() + client = speech.SpeechClient() with io.open(speech_file, 'rb') as audio_file: content = audio_file.read() @@ -61,9 +61,10 @@ def transcribe_file(speech_file): def transcribe_gcs(gcs_uri): """Asynchronously transcribes the audio file specified by the gcs_uri.""" - from google.cloud.speech import SpeechClient + from google.cloud import speech from google.cloud.speech import types - client = SpeechClient() + client = speech.SpeechClient() + audio = types.RecognitionAudio(uri=gcs_uri) config = types.RecognitionConfig( diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index fafb3b062b45..c6abee882c7c 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -28,9 +28,9 @@ def transcribe_streaming(stream_file): """Streams transcription of the given audio file.""" - from google.cloud.speech import SpeechClient + from google.cloud import speech from google.cloud.speech import types - client = SpeechClient() + client = speech.SpeechClient() with io.open(stream_file, 'rb') as audio_file: content = audio_file.read() From ce0d25dfc58f91db216fb26f89612e6871b11129 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Fri, 7 Jul 2017 10:16:37 -0700 Subject: [PATCH 15/29] flake --- speech/cloud-client/quickstart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py index 4f3c31464a26..45896b326a59 100644 --- a/speech/cloud-client/quickstart.py +++ b/speech/cloud-client/quickstart.py @@ -23,7 +23,7 @@ def run_quickstart(): # Imports the Google Cloud client library from google.cloud import speech from google.cloud.speech import types - + # Instantiates a client client = speech.SpeechClient() From 3196c732b09c1efc78cfe0ca1d43a1515cbf53e4 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 11 Jul 2017 10:14:01 -0700 Subject: [PATCH 16/29] correct indent --- speech/cloud-client/transcribe_streaming.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index c6abee882c7c..059ca4aa6ab1 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -50,9 +50,9 @@ def transcribe_streaming(stream_file): print('Finished: {}'.format(result.is_final)) print('Stability: {}'.format(result.stability)) alternatives = result.alternatives - for alternative in alternatives: - print('Confidence: {}'.format(alternative.confidence)) - print('Transcript: {}'.format(alternative.transcript)) + for alternative in alternatives: + print('Confidence: {}'.format(alternative.confidence)) + print('Transcript: {}'.format(alternative.transcript)) if __name__ == '__main__': From d5acd7c91c1f6647c0290e65a9e09ebf15fef91a Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 11 Jul 2017 10:46:48 -0700 Subject: [PATCH 17/29] migrate transcribe_streaming_mic to gapic --- .../cloud-client/transcribe_streaming_mic.py | 66 +++++++++---------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/speech/cloud-client/transcribe_streaming_mic.py b/speech/cloud-client/transcribe_streaming_mic.py index 3edd7588402c..bff2555bd8f9 100644 --- a/speech/cloud-client/transcribe_streaming_mic.py +++ b/speech/cloud-client/transcribe_streaming_mic.py @@ -32,6 +32,7 @@ import sys from google.cloud import speech +from google.cloud.speech import types import pyaudio from six.moves import queue # [END import_libraries] @@ -41,8 +42,8 @@ CHUNK = int(RATE / 10) # 100ms -class MicAsFile(object): - """Opens a recording stream as a file-like object.""" +class MicAsGenerator(object): + """Opens a recording stream as a generator yielding the audio chunks.""" def __init__(self, rate, chunk): self._rate = rate self._chunk = chunk @@ -82,27 +83,13 @@ def _fill_buffer(self, in_data, frame_count, time_info, status_flags): self._buff.put(in_data) return None, pyaudio.paContinue - def read(self, chunk_size): - if self.closed: - return - - # Use a blocking get() to ensure there's at least one chunk of data. - data = [self._buff.get()] - - # Now consume whatever other data's still buffered. + def generator(self): while True: - try: - data.append(self._buff.get(block=False)) - except queue.Empty: - break - - if self.closed: - return - return b''.join(data) + yield self._buff.get() # [END audio_stream] -def listen_print_loop(results_gen): +def listen_print_loop(responses): """Iterates through server responses and prints them. The results_gen passed is a generator that will block until a response @@ -114,12 +101,17 @@ def listen_print_loop(results_gen): final one, print a newline to preserve the finalized transcription. """ num_chars_printed = 0 - for result in results_gen: + for response in responses: + if not response.results: + continue + + # There could be multiple results in each response. + result = response.results[0] if not result.alternatives: continue - # Display the top transcription - transcript = result.transcript + # Display the top transcription of the top alternative. + transcript = result.alternatives[0].transcript # Display interim results, but with a carriage return at the end of the # line, so subsequent lines will overwrite them. @@ -147,21 +139,25 @@ def listen_print_loop(results_gen): def main(): - speech_client = speech.Client() - - with MicAsFile(RATE, CHUNK) as stream: - audio_sample = speech_client.sample( - stream=stream, - encoding=speech.encoding.Encoding.LINEAR16, - sample_rate_hertz=RATE) - # See http://g.co/cloud/speech/docs/languages - # for a list of supported languages. - language_code = 'en-US' # a BCP-47 language tag - results_gen = audio_sample.streaming_recognize( - language_code=language_code, interim_results=True) + # See http://g.co/cloud/speech/docs/languages + # for a list of supported languages. + language_code = 'en-US' # a BCP-47 language tag + + client = speech.SpeechClient() + config = types.RecognitionConfig( + encoding='LINEAR16', + sample_rate_hertz=RATE, + language_code=language_code) + streaming_config = types.StreamingRecognitionConfig(config=config, interim_results=True) + + with MicAsGenerator(RATE, CHUNK) as stream: + audio_generator = stream.generator() + requests = (types.StreamingRecognizeRequest(audio_content=content) for content in audio_generator) + + responses = client.streaming_recognize(streaming_config, requests) # Now, put the transcription responses to use. - listen_print_loop(results_gen) + listen_print_loop(responses) if __name__ == '__main__': From cb40b7f25c6c1185bb8cabf4c9a6a09c4fa0430e Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 11 Jul 2017 10:51:56 -0700 Subject: [PATCH 18/29] update google-cloud-speech version requirement --- speech/cloud-client/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speech/cloud-client/requirements.txt b/speech/cloud-client/requirements.txt index 7e574b31ea76..55fdd2f7bab5 100644 --- a/speech/cloud-client/requirements.txt +++ b/speech/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-speech==0.26.0 +google-cloud-speech>=0.27.0 From 34ce7588252f1c6662ba08ed0cf1d133b53c706a Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 11 Jul 2017 15:17:34 -0700 Subject: [PATCH 19/29] addressing review comments --- speech/cloud-client/transcribe_streaming_mic.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/speech/cloud-client/transcribe_streaming_mic.py b/speech/cloud-client/transcribe_streaming_mic.py index bff2555bd8f9..1a408052d7d0 100644 --- a/speech/cloud-client/transcribe_streaming_mic.py +++ b/speech/cloud-client/transcribe_streaming_mic.py @@ -42,7 +42,7 @@ CHUNK = int(RATE / 10) # 100ms -class MicAsGenerator(object): +class MicrophoneStream(object): """Opens a recording stream as a generator yielding the audio chunks.""" def __init__(self, rate, chunk): self._rate = rate @@ -84,7 +84,7 @@ def _fill_buffer(self, in_data, frame_count, time_info, status_flags): return None, pyaudio.paContinue def generator(self): - while True: + while not self.closed: yield self._buff.get() # [END audio_stream] @@ -110,7 +110,7 @@ def listen_print_loop(responses): if not result.alternatives: continue - # Display the top transcription of the top alternative. + # Display the transcription of the top alternative. transcript = result.alternatives[0].transcript # Display interim results, but with a carriage return at the end of the @@ -118,7 +118,7 @@ def listen_print_loop(responses): # # If the previous result was longer than this one, we need to print # some extra spaces to overwrite the previous result - overwrite_chars = ' ' * max(0, num_chars_printed - len(transcript)) + overwrite_chars = ' ' * (num_chars_printed - len(transcript)) if not result.is_final: sys.stdout.write(transcript + overwrite_chars + '\r') @@ -150,9 +150,10 @@ def main(): language_code=language_code) streaming_config = types.StreamingRecognitionConfig(config=config, interim_results=True) - with MicAsGenerator(RATE, CHUNK) as stream: + with MicrophoneStream(RATE, CHUNK) as stream: audio_generator = stream.generator() - requests = (types.StreamingRecognizeRequest(audio_content=content) for content in audio_generator) + requests = (types.StreamingRecognizeRequest(audio_content=content) + for content in audio_generator) responses = client.streaming_recognize(streaming_config, requests) From 09557936aa9d03173db9232bd97ab40f66de471e Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 11 Jul 2017 16:27:44 -0700 Subject: [PATCH 20/29] at the end of the audio stream, put None to signal to the generator --- .../cloud-client/transcribe_streaming_mic.py | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/speech/cloud-client/transcribe_streaming_mic.py b/speech/cloud-client/transcribe_streaming_mic.py index 1a408052d7d0..ab661f19787c 100644 --- a/speech/cloud-client/transcribe_streaming_mic.py +++ b/speech/cloud-client/transcribe_streaming_mic.py @@ -74,7 +74,8 @@ def __exit__(self, type, value, traceback): self._audio_stream.stop_stream() self._audio_stream.close() self.closed = True - # Flush out the read, just in case + # Signal the generator to terminate so that the client's + # streaming_recognize method will not block the process termination. self._buff.put(None) self._audio_interface.terminate() @@ -85,7 +86,25 @@ def _fill_buffer(self, in_data, frame_count, time_info, status_flags): def generator(self): while not self.closed: - yield self._buff.get() + # Use a blocking get() to ensure there's at least one chunk of data. + # Stop iteration if the chunk is None, indicating the end of the + # audio stream. + chunk = self._buff.get() + if chunk is None: + return + data = [chunk] + + # Now consume whatever other data's still buffered. + while True: + try: + chunk = self._buff.get(block=False) + if chunk is None: + return + data.append(chunk) + except queue.Empty: + break + + yield b''.join(data) # [END audio_stream] From e355325b00fadf52f408acb6330c9566d874fdde Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 12 Jul 2017 07:55:45 -0700 Subject: [PATCH 21/29] flake --- speech/cloud-client/transcribe_streaming_mic.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/speech/cloud-client/transcribe_streaming_mic.py b/speech/cloud-client/transcribe_streaming_mic.py index ab661f19787c..0be3ea9746c2 100644 --- a/speech/cloud-client/transcribe_streaming_mic.py +++ b/speech/cloud-client/transcribe_streaming_mic.py @@ -86,9 +86,9 @@ def _fill_buffer(self, in_data, frame_count, time_info, status_flags): def generator(self): while not self.closed: - # Use a blocking get() to ensure there's at least one chunk of data. - # Stop iteration if the chunk is None, indicating the end of the - # audio stream. + # Use a blocking get() to ensure there's at least one chunk of + # data, and stop iteration if the chunk is None, indicating the + # end of the audio stream. chunk = self._buff.get() if chunk is None: return @@ -167,7 +167,8 @@ def main(): encoding='LINEAR16', sample_rate_hertz=RATE, language_code=language_code) - streaming_config = types.StreamingRecognitionConfig(config=config, interim_results=True) + streaming_config = types.StreamingRecognitionConfig(config=config, + interim_results=True) with MicrophoneStream(RATE, CHUNK) as stream: audio_generator = stream.generator() From a5f4c350c7fe53155a7cfb767e1a4d443807c366 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 12 Jul 2017 14:13:43 -0700 Subject: [PATCH 22/29] addressing github review comments --- speech/cloud-client/requirements.txt | 2 +- speech/cloud-client/transcribe_streaming.py | 4 ++-- speech/cloud-client/transcribe_streaming_mic.py | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/speech/cloud-client/requirements.txt b/speech/cloud-client/requirements.txt index 55fdd2f7bab5..929705305601 100644 --- a/speech/cloud-client/requirements.txt +++ b/speech/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-speech>=0.27.0 +google-cloud-speech==0.27.0 diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 059ca4aa6ab1..574d4add8ee1 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -34,7 +34,6 @@ def transcribe_streaming(stream_file): with io.open(stream_file, 'rb') as audio_file: content = audio_file.read() - request = types.StreamingRecognizeRequest(audio_content=content) config = types.RecognitionConfig( encoding='LINEAR16', @@ -42,7 +41,8 @@ def transcribe_streaming(stream_file): language_code='en-US') # In practice requests should be a generator yielding chunks of audio data. - requests = [request] + requests = (types.StreamingRecognizeRequest(audio_content=c) + for c in [content]) streaming_config = types.StreamingRecognitionConfig(config=config) for response in client.streaming_recognize(streaming_config, requests): diff --git a/speech/cloud-client/transcribe_streaming_mic.py b/speech/cloud-client/transcribe_streaming_mic.py index 0be3ea9746c2..2ff8fe5d2ab2 100644 --- a/speech/cloud-client/transcribe_streaming_mic.py +++ b/speech/cloud-client/transcribe_streaming_mic.py @@ -111,8 +111,12 @@ def generator(self): def listen_print_loop(responses): """Iterates through server responses and prints them. - The results_gen passed is a generator that will block until a response - is provided by the server. When the transcription response comes, print it. + The responses passed is a generator that will block until a response + is provided by the server. + + Each response may contain multiple results, and each result may contain + multiple alternatives; for details, see https://goo.gl/tjCPAU. Here we + print only the transcription for the top alternative of the top result. In this case, responses are provided for interim results as well. If the response is an interim one, print a line feed at the end of it, to allow From 73d2b799b4637b778ec1e427e80c05f74a6e177a Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 13 Jul 2017 14:00:24 -0700 Subject: [PATCH 23/29] add region tags for migration guide --- speech/cloud-client/README.rst.in | 2 ++ speech/cloud-client/quickstart.py | 4 ++++ speech/cloud-client/transcribe.py | 11 +++++++++-- speech/cloud-client/transcribe_async.py | 8 ++++++-- speech/cloud-client/transcribe_streaming.py | 18 +++++++++++++----- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/speech/cloud-client/README.rst.in b/speech/cloud-client/README.rst.in index 7025931873b4..5c1b9af69a30 100644 --- a/speech/cloud-client/README.rst.in +++ b/speech/cloud-client/README.rst.in @@ -9,6 +9,8 @@ product: recognition technologies into developer applications. Send audio and receive a text transcription from the Cloud Speech API service. + See the [migration guide](/docs/python-client-migration) for information about migrating to Python client library v0.27. + setup: - auth - install_deps diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py index 45896b326a59..7b294b5f6548 100644 --- a/speech/cloud-client/quickstart.py +++ b/speech/cloud-client/quickstart.py @@ -21,11 +21,15 @@ def run_quickstart(): import os # Imports the Google Cloud client library + # [START migration_import] from google.cloud import speech from google.cloud.speech import types + # [END migration_import] # Instantiates a client + # [START migration_client] client = speech.SpeechClient() + # [END migration_client] # The name of the audio file to transcribe file_name = os.path.join( diff --git a/speech/cloud-client/transcribe.py b/speech/cloud-client/transcribe.py index 830e223bd5b1..30dc411ccfcc 100644 --- a/speech/cloud-client/transcribe.py +++ b/speech/cloud-client/transcribe.py @@ -34,20 +34,26 @@ def transcribe_file(speech_file): from google.cloud.speech import types client = speech.SpeechClient() + # [START migration_sync_request] + # [START migration_audio_config_file] with io.open(speech_file, 'rb') as audio_file: content = audio_file.read() - audio = types.RecognitionAudio(content=content) + audio = types.RecognitionAudio(content=content) config = types.RecognitionConfig( encoding='LINEAR16', sample_rate_hertz=16000, language_code='en-US') + # [END migration_audio_config_file] + # [START migration_sync_response] response = client.recognize(config, audio) + # [END migration_sync_request] alternatives = response.results[0].alternatives for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) + # [END migration_sync_response] def transcribe_gcs(gcs_uri): @@ -56,12 +62,13 @@ def transcribe_gcs(gcs_uri): from google.cloud.speech import types client = speech.SpeechClient() + # [START migration_audio_config_gcs] audio = types.RecognitionAudio(uri=gcs_uri) - config = types.RecognitionConfig( encoding='FLAC', sample_rate_hertz=16000, language_code='en-US') + # [END migration_audio_config_gcs] response = client.recognize(config, audio) alternatives = response.results[0].alternatives diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index e40404c2ac8b..4b6ab3ed333e 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -33,17 +33,21 @@ def transcribe_file(speech_file): from google.cloud.speech import types client = speech.SpeechClient() + # [START migration_async_request] with io.open(speech_file, 'rb') as audio_file: content = audio_file.read() - audio = types.RecognitionAudio(content=content) + audio = types.RecognitionAudio(content=content) config = types.RecognitionConfig( encoding='LINEAR16', sample_rate_hertz=16000, language_code='en-US') + # [START migration_async_response] operation = client.long_running_recognize(config, audio) + # [END migration_async_request] + # Sleep and poll the operation.done() retry_count = 100 while retry_count > 0 and not operation.done(): retry_count -= 1 @@ -57,6 +61,7 @@ def transcribe_file(speech_file): for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) print('Confidence: {}'.format(alternative.confidence)) + # [END migration_async_response] def transcribe_gcs(gcs_uri): @@ -66,7 +71,6 @@ def transcribe_gcs(gcs_uri): client = speech.SpeechClient() audio = types.RecognitionAudio(uri=gcs_uri) - config = types.RecognitionConfig( encoding='FLAC', sample_rate_hertz=16000, diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 574d4add8ee1..9a648ebbf61d 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -32,20 +32,27 @@ def transcribe_streaming(stream_file): from google.cloud.speech import types client = speech.SpeechClient() + # [START migration_streaming_request] with io.open(stream_file, 'rb') as audio_file: content = audio_file.read() + # In practice, stream should be a generator yielding chunks of audio data. + stream = [content] + requests = (types.StreamingRecognizeRequest(audio_content=c) + for c in stream) + config = types.RecognitionConfig( encoding='LINEAR16', sample_rate_hertz=16000, language_code='en-US') - - # In practice requests should be a generator yielding chunks of audio data. - requests = (types.StreamingRecognizeRequest(audio_content=c) - for c in [content]) streaming_config = types.StreamingRecognitionConfig(config=config) - for response in client.streaming_recognize(streaming_config, requests): + # streaming_recognize returns a generator. + # [START migration_streaming_response] + responses = client.streaming_recognize(streaming_config, requests) + # [END migration_streaming_request] + + for response in responses: for result in response.results: print('Finished: {}'.format(result.is_final)) print('Stability: {}'.format(result.stability)) @@ -53,6 +60,7 @@ def transcribe_streaming(stream_file): for alternative in alternatives: print('Confidence: {}'.format(alternative.confidence)) print('Transcript: {}'.format(alternative.transcript)) + # [END migration_streaming_response] if __name__ == '__main__': From 39f9b6b9ec7272b53bed5376fbccabbb35c78c97 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 13 Jul 2017 14:03:38 -0700 Subject: [PATCH 24/29] update README --- speech/cloud-client/README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/speech/cloud-client/README.rst b/speech/cloud-client/README.rst index 70fdd92b0682..deeb882597bd 100644 --- a/speech/cloud-client/README.rst +++ b/speech/cloud-client/README.rst @@ -4,6 +4,7 @@ Google Cloud Speech API Python Samples =============================================================================== This directory contains samples for Google Cloud Speech API. The `Google Cloud Speech API`_ enables easy integration of Google speech recognition technologies into developer applications. Send audio and receive a text transcription from the Cloud Speech API service. +See the [migration guide](/docs/python-client-migration) for information about migrating to Python client library v0.27. From efe110c50e5c4d0f5513b58441634495c2426350 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 13 Jul 2017 14:11:45 -0700 Subject: [PATCH 25/29] rst format --- speech/cloud-client/README.rst | 5 ++++- speech/cloud-client/README.rst.in | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/speech/cloud-client/README.rst b/speech/cloud-client/README.rst index deeb882597bd..5bbf165bf0d4 100644 --- a/speech/cloud-client/README.rst +++ b/speech/cloud-client/README.rst @@ -4,7 +4,10 @@ Google Cloud Speech API Python Samples =============================================================================== This directory contains samples for Google Cloud Speech API. The `Google Cloud Speech API`_ enables easy integration of Google speech recognition technologies into developer applications. Send audio and receive a text transcription from the Cloud Speech API service. -See the [migration guide](/docs/python-client-migration) for information about migrating to Python client library v0.27. + +See the `migration guide`_ for information about migrating to Python client library v0.27. + +.. _migration guide: https://cloud.google.com/speech/docs/python-client-migration diff --git a/speech/cloud-client/README.rst.in b/speech/cloud-client/README.rst.in index 5c1b9af69a30..6e13fb84faac 100644 --- a/speech/cloud-client/README.rst.in +++ b/speech/cloud-client/README.rst.in @@ -9,7 +9,11 @@ product: recognition technologies into developer applications. Send audio and receive a text transcription from the Cloud Speech API service. - See the [migration guide](/docs/python-client-migration) for information about migrating to Python client library v0.27. + + See the `migration guide`_ for information about migrating to Python client library v0.27. + + + .. _migration guide: https://cloud.google.com/speech/docs/python-client-migration setup: - auth From 1f4cda6849defd8697ed83f66595e8cbfd00b527 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 13 Jul 2017 14:13:24 -0700 Subject: [PATCH 26/29] bullet --- speech/cloud-client/README.rst | 2 +- speech/cloud-client/README.rst.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/speech/cloud-client/README.rst b/speech/cloud-client/README.rst index 5bbf165bf0d4..761ebdf6ee86 100644 --- a/speech/cloud-client/README.rst +++ b/speech/cloud-client/README.rst @@ -5,7 +5,7 @@ Google Cloud Speech API Python Samples This directory contains samples for Google Cloud Speech API. The `Google Cloud Speech API`_ enables easy integration of Google speech recognition technologies into developer applications. Send audio and receive a text transcription from the Cloud Speech API service. -See the `migration guide`_ for information about migrating to Python client library v0.27. +- See the `migration guide`_ for information about migrating to Python client library v0.27. .. _migration guide: https://cloud.google.com/speech/docs/python-client-migration diff --git a/speech/cloud-client/README.rst.in b/speech/cloud-client/README.rst.in index 6e13fb84faac..9b671369b0e0 100644 --- a/speech/cloud-client/README.rst.in +++ b/speech/cloud-client/README.rst.in @@ -10,7 +10,7 @@ product: a text transcription from the Cloud Speech API service. - See the `migration guide`_ for information about migrating to Python client library v0.27. + - See the `migration guide`_ for information about migrating to Python client library v0.27. .. _migration guide: https://cloud.google.com/speech/docs/python-client-migration From bd32ab4193f41b1b98523c01c854c62647fe7558 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 13 Jul 2017 14:29:11 -0700 Subject: [PATCH 27/29] addressing PR review comments --- speech/cloud-client/transcribe_streaming.py | 4 ++-- speech/cloud-client/transcribe_streaming_mic.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 9a648ebbf61d..9c200f34dd3e 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -38,8 +38,8 @@ def transcribe_streaming(stream_file): # In practice, stream should be a generator yielding chunks of audio data. stream = [content] - requests = (types.StreamingRecognizeRequest(audio_content=c) - for c in stream) + requests = (types.StreamingRecognizeRequest(audio_content=chunk) + for chunk in stream) config = types.RecognitionConfig( encoding='LINEAR16', diff --git a/speech/cloud-client/transcribe_streaming_mic.py b/speech/cloud-client/transcribe_streaming_mic.py index 2ff8fe5d2ab2..5a770f167c4f 100644 --- a/speech/cloud-client/transcribe_streaming_mic.py +++ b/speech/cloud-client/transcribe_streaming_mic.py @@ -171,8 +171,9 @@ def main(): encoding='LINEAR16', sample_rate_hertz=RATE, language_code=language_code) - streaming_config = types.StreamingRecognitionConfig(config=config, - interim_results=True) + streaming_config = types.StreamingRecognitionConfig( + config=config, + interim_results=True) with MicrophoneStream(RATE, CHUNK) as stream: audio_generator = stream.generator() From 1f861eeb427aed60256f372b17f1cefd27f6779a Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 13 Jul 2017 16:05:41 -0700 Subject: [PATCH 28/29] use enums --- speech/cloud-client/quickstart.py | 3 ++- speech/cloud-client/transcribe.py | 6 ++++-- speech/cloud-client/transcribe_async.py | 6 ++++-- speech/cloud-client/transcribe_streaming.py | 3 ++- speech/cloud-client/transcribe_streaming_mic.py | 3 ++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py index 7b294b5f6548..388e7ffc55aa 100644 --- a/speech/cloud-client/quickstart.py +++ b/speech/cloud-client/quickstart.py @@ -23,6 +23,7 @@ def run_quickstart(): # Imports the Google Cloud client library # [START migration_import] from google.cloud import speech + from google.cloud.speech import enums from google.cloud.speech import types # [END migration_import] @@ -43,7 +44,7 @@ def run_quickstart(): audio = types.RecognitionAudio(content=content) config = types.RecognitionConfig( - encoding='LINEAR16', + encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=16000, language_code='en-US') diff --git a/speech/cloud-client/transcribe.py b/speech/cloud-client/transcribe.py index 30dc411ccfcc..6bd74354765e 100644 --- a/speech/cloud-client/transcribe.py +++ b/speech/cloud-client/transcribe.py @@ -31,6 +31,7 @@ def transcribe_file(speech_file): """Transcribe the given audio file.""" from google.cloud import speech + from google.cloud.speech import enums from google.cloud.speech import types client = speech.SpeechClient() @@ -41,7 +42,7 @@ def transcribe_file(speech_file): audio = types.RecognitionAudio(content=content) config = types.RecognitionConfig( - encoding='LINEAR16', + encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=16000, language_code='en-US') # [END migration_audio_config_file] @@ -59,13 +60,14 @@ def transcribe_file(speech_file): def transcribe_gcs(gcs_uri): """Transcribes the audio file specified by the gcs_uri.""" from google.cloud import speech + from google.cloud.speech import enums from google.cloud.speech import types client = speech.SpeechClient() # [START migration_audio_config_gcs] audio = types.RecognitionAudio(uri=gcs_uri) config = types.RecognitionConfig( - encoding='FLAC', + encoding=enums.RecognitionConfig.AudioEncoding.FLAC, sample_rate_hertz=16000, language_code='en-US') # [END migration_audio_config_gcs] diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index 4b6ab3ed333e..9cac1d2174ca 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -30,6 +30,7 @@ def transcribe_file(speech_file): """Transcribe the given audio file asynchronously.""" from google.cloud import speech + from google.cloud.speech import enums from google.cloud.speech import types client = speech.SpeechClient() @@ -39,7 +40,7 @@ def transcribe_file(speech_file): audio = types.RecognitionAudio(content=content) config = types.RecognitionConfig( - encoding='LINEAR16', + encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=16000, language_code='en-US') @@ -67,12 +68,13 @@ def transcribe_file(speech_file): def transcribe_gcs(gcs_uri): """Asynchronously transcribes the audio file specified by the gcs_uri.""" from google.cloud import speech + from google.cloud.speech import enums from google.cloud.speech import types client = speech.SpeechClient() audio = types.RecognitionAudio(uri=gcs_uri) config = types.RecognitionConfig( - encoding='FLAC', + encoding=enums.RecognitionConfig.AudioEncoding.FLAC, sample_rate_hertz=16000, language_code='en-US') diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 9c200f34dd3e..455a470fcd79 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -29,6 +29,7 @@ def transcribe_streaming(stream_file): """Streams transcription of the given audio file.""" from google.cloud import speech + from google.cloud.speech import enums from google.cloud.speech import types client = speech.SpeechClient() @@ -42,7 +43,7 @@ def transcribe_streaming(stream_file): for chunk in stream) config = types.RecognitionConfig( - encoding='LINEAR16', + encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=16000, language_code='en-US') streaming_config = types.StreamingRecognitionConfig(config=config) diff --git a/speech/cloud-client/transcribe_streaming_mic.py b/speech/cloud-client/transcribe_streaming_mic.py index 5a770f167c4f..bde8b30f1687 100644 --- a/speech/cloud-client/transcribe_streaming_mic.py +++ b/speech/cloud-client/transcribe_streaming_mic.py @@ -32,6 +32,7 @@ import sys from google.cloud import speech +from google.cloud.speech import enums from google.cloud.speech import types import pyaudio from six.moves import queue @@ -168,7 +169,7 @@ def main(): client = speech.SpeechClient() config = types.RecognitionConfig( - encoding='LINEAR16', + encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=RATE, language_code=language_code) streaming_config = types.StreamingRecognitionConfig( From 8fa29829e142eb1dff8782b7ec7309a91d00da87 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 13 Jul 2017 16:25:18 -0700 Subject: [PATCH 29/29] remove a word --- speech/cloud-client/transcribe_async.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index 9cac1d2174ca..65215e90210d 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -48,7 +48,7 @@ def transcribe_file(speech_file): operation = client.long_running_recognize(config, audio) # [END migration_async_request] - # Sleep and poll the operation.done() + # Sleep and poll operation.done() retry_count = 100 while retry_count > 0 and not operation.done(): retry_count -= 1