diff --git a/samples/snippets/README.rst b/samples/snippets/README.rst index a8a84205..c0d970f2 100644 --- a/samples/snippets/README.rst +++ b/samples/snippets/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/samples/snippets/README.rst.in b/samples/snippets/README.rst.in index c757d47d..70259318 100644 --- a/samples/snippets/README.rst.in +++ b/samples/snippets/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/samples/snippets/quickstart.py b/samples/snippets/quickstart.py index 7a0a798c..81966cf8 100644 --- a/samples/snippets/quickstart.py +++ b/samples/snippets/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 = sample.recognize('en-US') for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 186ea352..deb66fca 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1 +1 @@ -google-cloud-speech==0.23.0 +google-cloud-speech==0.25.0 diff --git a/samples/snippets/transcribe.py b/samples/snippets/transcribe.py index fbf57b20..7c138ec9 100644 --- a/samples/snippets/transcribe.py +++ b/samples/snippets/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 = audio_sample.recognize('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 = audio_sample.recognize('en-US') for alternative in alternatives: print('Transcript: {}'.format(alternative.transcript)) diff --git a/samples/snippets/transcribe_async.py b/samples/snippets/transcribe_async.py index d7a8fce0..8457871b 100644 --- a/samples/snippets/transcribe_async.py +++ b/samples/snippets/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 @@ -38,9 +38,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 = 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', - sample_rate=16000) + encoding='LINEAR16', + sample_rate_hertz=16000) - operation = speech_client.speech_api.async_recognize(audio_sample) + operation = audio_sample.long_running_recognize('en-US') retry_count = 100 while retry_count > 0 and not operation.complete: diff --git a/samples/snippets/transcribe_async_test.py b/samples/snippets/transcribe_async_test.py index 7d66747e..8d719753 100644 --- a/samples/snippets/transcribe_async_test.py +++ b/samples/snippets/transcribe_async_test.py @@ -29,7 +29,7 @@ def test_transcribe(capsys): def test_transcribe_gcs(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/samples/snippets/transcribe_streaming.py b/samples/snippets/transcribe_streaming.py index 0643af7b..bdf35314 100644 --- a/samples/snippets/transcribe_streaming.py +++ b/samples/snippets/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))