From 50038ecb5a5f7a4e12cdc0e66c09bd4455c0914d Mon Sep 17 00:00:00 2001 From: Gus Class Date: Mon, 3 Apr 2017 13:16:22 -0700 Subject: [PATCH 1/6] Updates library version. --- language/cloud-client/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language/cloud-client/requirements.txt b/language/cloud-client/requirements.txt index f1dafd7e696d..9b608a045a77 100644 --- a/language/cloud-client/requirements.txt +++ b/language/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-language==0.23.1 +google-cloud-language==0.24.0 From 80e7c6a84ad8debc0ff9c57c8e3a50494bcb6eab Mon Sep 17 00:00:00 2001 From: Gus Class Date: Tue, 4 Apr 2017 14:23:25 -0700 Subject: [PATCH 2/6] Updates speech for v1 changes --- speech/cloud-client/README.rst | 25 +++++++++++++++++++++ speech/cloud-client/README.rst.in | 3 +++ speech/cloud-client/quickstart.py | 6 ++--- speech/cloud-client/requirements.txt | 2 +- speech/cloud-client/transcribe.py | 8 +++---- speech/cloud-client/transcribe_async.py | 10 +++++---- speech/cloud-client/transcribe_streaming.py | 4 ++-- 7 files changed, 44 insertions(+), 14 deletions(-) diff --git a/speech/cloud-client/README.rst b/speech/cloud-client/README.rst index a8a842059b66..c0d970f273e3 100644 --- a/speech/cloud-client/README.rst +++ b/speech/cloud-client/README.rst @@ -136,6 +136,31 @@ To run this sample: -h, --help show this help message and exit +Transcribe Streaming ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + + +To run this sample: + +.. code-block:: bash + + $ python transcribe_streaming.py + + usage: transcribe_streaming.py [-h] stream + + Google Cloud Speech API sample application using the streaming API. + + Example usage: + python transcribe_streaming.py resources/audio.raw + + positional arguments: + stream File to stream to the API + + optional arguments: + -h, --help show this help message and exit + + The client library diff --git a/speech/cloud-client/README.rst.in b/speech/cloud-client/README.rst.in index c757d47d5d55..7025931873b4 100644 --- a/speech/cloud-client/README.rst.in +++ b/speech/cloud-client/README.rst.in @@ -22,5 +22,8 @@ samples: - name: Transcribe async file: transcribe_async.py show_help: true +- name: Transcribe Streaming + file: transcribe_streaming.py + show_help: true cloud_client_library: true diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py index 7a0a798cd280..3b443bf1bbad 100644 --- a/speech/cloud-client/quickstart.py +++ b/speech/cloud-client/quickstart.py @@ -35,14 +35,14 @@ def run_quickstart(): # Loads the audio into memory with io.open(file_name, 'rb') as audio_file: content = audio_file.read() - audio_sample = speech_client.sample( + sample = speech_client.sample( content, source_uri=None, encoding='LINEAR16', - sample_rate=16000) + sample_rate_hertz=16000) # Detects speech in the audio file - alternatives = speech_client.speech_api.sync_recognize(audio_sample) + alternatives = speech_client.speech_api.recognize(sample, 'en-US') for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) diff --git a/speech/cloud-client/requirements.txt b/speech/cloud-client/requirements.txt index 186ea3523769..1a0cb492b62c 100644 --- a/speech/cloud-client/requirements.txt +++ b/speech/cloud-client/requirements.txt @@ -1 +1 @@ -google-cloud-speech==0.23.0 +https://storage.googleapis.com/api-client-staging/speech-v1-python.zip diff --git a/speech/cloud-client/transcribe.py b/speech/cloud-client/transcribe.py index fbf57b2019fd..201eb026c02e 100644 --- a/speech/cloud-client/transcribe.py +++ b/speech/cloud-client/transcribe.py @@ -39,9 +39,9 @@ def transcribe_file(speech_file): content=content, source_uri=None, encoding='LINEAR16', - sample_rate=16000) + sample_rate_hertz=16000) - alternatives = speech_client.speech_api.sync_recognize(audio_sample) + alternatives = speech_client.speech_api.recognize(audio_sample, 'en-US') for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) @@ -55,9 +55,9 @@ def transcribe_gcs(gcs_uri): content=None, source_uri=gcs_uri, encoding='FLAC', - sample_rate=16000) + sample_rate_hertz=16000) - alternatives = speech_client.speech_api.sync_recognize(audio_sample) + alternatives = speech_client.speech_api.recognize(audio_sample, 'en-US') for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index d7a8fce05edb..bce0ab98ae6e 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -31,6 +31,7 @@ def transcribe_file(speech_file): """Transcribe the given audio file asynchronously.""" from google.cloud import speech speech_client = speech.Client() + speech_api = speech_client.speech_api with io.open(speech_file, 'rb') as audio_file: content = audio_file.read() @@ -38,9 +39,9 @@ def transcribe_file(speech_file): content, source_uri=None, encoding='LINEAR16', - sample_rate=16000) + sample_rate_hertz=16000) - operation = speech_client.speech_api.async_recognize(audio_sample) + operation = speech_api.long_running_recognize(audio_sample, 'en-US') retry_count = 100 while retry_count > 0 and not operation.complete: @@ -63,14 +64,15 @@ def transcribe_gcs(gcs_uri): """Asynchronously transcribes the audio file specified by the gcs_uri.""" from google.cloud import speech speech_client = speech.Client() + speech_api = speech_client.speech_api audio_sample = speech_client.sample( content=None, source_uri=gcs_uri, encoding='FLAC', - sample_rate=16000) + sample_rate_hertz=16000) - operation = speech_client.speech_api.async_recognize(audio_sample) + operation = speech_api.long_running_recognize(audio_sample, 'en-US') retry_count = 100 while retry_count > 0 and not operation.complete: diff --git a/speech/cloud-client/transcribe_streaming.py b/speech/cloud-client/transcribe_streaming.py index 0643af7bbe83..bdf35314d06d 100644 --- a/speech/cloud-client/transcribe_streaming.py +++ b/speech/cloud-client/transcribe_streaming.py @@ -35,8 +35,8 @@ def transcribe_streaming(stream_file): audio_sample = speech_client.sample( stream=audio_file, encoding=speech.encoding.Encoding.LINEAR16, - sample_rate=16000) - alternatives = audio_sample.streaming_recognize() + sample_rate_hertz=16000) + alternatives = audio_sample.streaming_recognize('en-US') for alternative in alternatives: print('Finished: {}'.format(alternative.is_final)) From bd7692b00da7076051e89d0c8c66f78e3334d185 Mon Sep 17 00:00:00 2001 From: Gus Class Date: Wed, 5 Apr 2017 13:44:16 -0700 Subject: [PATCH 3/6] Use audio_sample for transcription instead of client --- speech/cloud-client/quickstart.py | 2 +- speech/cloud-client/transcribe.py | 4 ++-- speech/cloud-client/transcribe_async.py | 6 ++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py index 3b443bf1bbad..81966cf8d336 100644 --- a/speech/cloud-client/quickstart.py +++ b/speech/cloud-client/quickstart.py @@ -42,7 +42,7 @@ def run_quickstart(): sample_rate_hertz=16000) # Detects speech in the audio file - alternatives = speech_client.speech_api.recognize(sample, 'en-US') + alternatives = sample.recognize('en-US') for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) diff --git a/speech/cloud-client/transcribe.py b/speech/cloud-client/transcribe.py index 201eb026c02e..6974efe62d36 100644 --- a/speech/cloud-client/transcribe.py +++ b/speech/cloud-client/transcribe.py @@ -41,7 +41,7 @@ def transcribe_file(speech_file): encoding='LINEAR16', sample_rate_hertz=16000) - alternatives = speech_client.speech_api.recognize(audio_sample, 'en-US') + alternatives = audio_sample.recognize('en-US') for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) @@ -57,7 +57,7 @@ def transcribe_gcs(gcs_uri): encoding='FLAC', sample_rate_hertz=16000) - alternatives = speech_client.speech_api.recognize(audio_sample, 'en-US') + alternatives = audio_sample.recognize(audio_sample, 'en-US') for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index bce0ab98ae6e..74d2c1eb7dc2 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -31,7 +31,6 @@ def transcribe_file(speech_file): """Transcribe the given audio file asynchronously.""" from google.cloud import speech speech_client = speech.Client() - speech_api = speech_client.speech_api with io.open(speech_file, 'rb') as audio_file: content = audio_file.read() @@ -41,7 +40,7 @@ def transcribe_file(speech_file): encoding='LINEAR16', sample_rate_hertz=16000) - operation = speech_api.long_running_recognize(audio_sample, 'en-US') + operation = audio_sample.long_running_recognize(audio_sample, 'en-US') retry_count = 100 while retry_count > 0 and not operation.complete: @@ -64,7 +63,6 @@ def transcribe_gcs(gcs_uri): """Asynchronously transcribes the audio file specified by the gcs_uri.""" from google.cloud import speech speech_client = speech.Client() - speech_api = speech_client.speech_api audio_sample = speech_client.sample( content=None, @@ -72,7 +70,7 @@ def transcribe_gcs(gcs_uri): encoding='FLAC', sample_rate_hertz=16000) - operation = speech_api.long_running_recognize(audio_sample, 'en-US') + operation = audio_sample.long_running_recognize(audio_sample, 'en-US') retry_count = 100 while retry_count > 0 and not operation.complete: From deca26123de0423671203381d489073cd71bb4bd Mon Sep 17 00:00:00 2001 From: Gus Class Date: Wed, 5 Apr 2017 15:24:36 -0700 Subject: [PATCH 4/6] Removes extra parameter, changes async GCS test to use raw. --- speech/cloud-client/transcribe.py | 2 +- speech/cloud-client/transcribe_async.py | 8 ++++---- speech/cloud-client/transcribe_async_test.py | 2 +- speech/cloud-client/transcribe_test.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/speech/cloud-client/transcribe.py b/speech/cloud-client/transcribe.py index 6974efe62d36..7c138ec963a4 100644 --- a/speech/cloud-client/transcribe.py +++ b/speech/cloud-client/transcribe.py @@ -57,7 +57,7 @@ def transcribe_gcs(gcs_uri): encoding='FLAC', sample_rate_hertz=16000) - alternatives = audio_sample.recognize(audio_sample, 'en-US') + alternatives = audio_sample.recognize('en-US') for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) diff --git a/speech/cloud-client/transcribe_async.py b/speech/cloud-client/transcribe_async.py index 74d2c1eb7dc2..8457871b3d7a 100644 --- a/speech/cloud-client/transcribe_async.py +++ b/speech/cloud-client/transcribe_async.py @@ -19,7 +19,7 @@ Example usage: python transcribe_async.py resources/audio.raw - python transcribe_async.py gs://cloud-samples-tests/speech/brooklyn.flac + python transcribe_async.py gs://cloud-samples-tests/speech/brooklyn.raw """ import argparse @@ -40,7 +40,7 @@ def transcribe_file(speech_file): encoding='LINEAR16', sample_rate_hertz=16000) - operation = audio_sample.long_running_recognize(audio_sample, 'en-US') + operation = audio_sample.long_running_recognize('en-US') retry_count = 100 while retry_count > 0 and not operation.complete: @@ -67,10 +67,10 @@ def transcribe_gcs(gcs_uri): audio_sample = speech_client.sample( content=None, source_uri=gcs_uri, - encoding='FLAC', + encoding='LINEAR16', sample_rate_hertz=16000) - operation = audio_sample.long_running_recognize(audio_sample, 'en-US') + operation = audio_sample.long_running_recognize('en-US') retry_count = 100 while retry_count > 0 and not operation.complete: diff --git a/speech/cloud-client/transcribe_async_test.py b/speech/cloud-client/transcribe_async_test.py index 6142d43db96b..592f12c92c19 100644 --- a/speech/cloud-client/transcribe_async_test.py +++ b/speech/cloud-client/transcribe_async_test.py @@ -25,7 +25,7 @@ def test_transcribe(resource, capsys): def test_transcribe_gcs(resource, capsys): transcribe_async.transcribe_gcs( - 'gs://python-docs-samples-tests/speech/audio.flac') + 'gs://python-docs-samples-tests/speech/audio.raw') out, err = capsys.readouterr() assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I) diff --git a/speech/cloud-client/transcribe_test.py b/speech/cloud-client/transcribe_test.py index 5940fc7f9862..9af52304d63b 100644 --- a/speech/cloud-client/transcribe_test.py +++ b/speech/cloud-client/transcribe_test.py @@ -25,7 +25,7 @@ def test_transcribe_file(resource, capsys): def test_transcribe_gcs(resource, capsys): transcribe.transcribe_gcs( - 'gs://python-docs-samples-tests/speech/audio.flac') + 'gs://python-docs-samples-tests/speech/audio.raw') out, err = capsys.readouterr() assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I) From 5968c192559d0925963e0172e9ded0277c4a1cca Mon Sep 17 00:00:00 2001 From: Gus Class Date: Wed, 5 Apr 2017 15:26:36 -0700 Subject: [PATCH 5/6] Fixes test. --- speech/cloud-client/transcribe_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speech/cloud-client/transcribe_test.py b/speech/cloud-client/transcribe_test.py index 9af52304d63b..5940fc7f9862 100644 --- a/speech/cloud-client/transcribe_test.py +++ b/speech/cloud-client/transcribe_test.py @@ -25,7 +25,7 @@ def test_transcribe_file(resource, capsys): def test_transcribe_gcs(resource, capsys): transcribe.transcribe_gcs( - 'gs://python-docs-samples-tests/speech/audio.raw') + 'gs://python-docs-samples-tests/speech/audio.flac') out, err = capsys.readouterr() assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I) From 363221ac3c539f686acdcc9d30ea8a4aff32b756 Mon Sep 17 00:00:00 2001 From: Gus Class Date: Fri, 7 Apr 2017 12:48:29 -0700 Subject: [PATCH 6/6] Update to v1 speech Google Cloud client library --- 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 1a0cb492b62c..deb66fcac830 100644 --- a/speech/cloud-client/requirements.txt +++ b/speech/cloud-client/requirements.txt @@ -1 +1 @@ -https://storage.googleapis.com/api-client-staging/speech-v1-python.zip +google-cloud-speech==0.25.0