Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speech v1 #3266

Merged
merged 7 commits into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions docs/speech-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ create an instance of :class:`~google.cloud.speech.client.Client`.
Asynchronous Recognition
------------------------

The :meth:`~google.cloud.speech.Client.async_recognize` sends audio data to the
Speech API and initiates a Long Running Operation. Using this operation, you
can periodically poll for recognition results. Use asynchronous requests for
audio data of any duration up to 80 minutes.
The :meth:`~google.cloud.speech.Client.long_running_recognize` sends audio
data to the Speech API and initiates a Long Running Operation. Using this
operation, you can periodically poll for recognition results. Use asynchronous
requests for audio data of any duration up to 80 minutes.

.. note::

Expand All @@ -54,8 +54,11 @@ See: `Speech Asynchronous Recognize`_
>>> client = speech.Client()
>>> sample = client.sample(source_uri='gs://my-bucket/recording.flac',
... encoding=speech.Encoding.LINEAR16,
... sample_rate=44100)
>>> operation = sample.async_recognize(max_alternatives=2)
... sample_rate_hertz=44100)
>>> operation = sample.long_running_recognize(
... language_code='en-US',
... max_alternatives=2,
... )
>>> retry_count = 100
>>> while retry_count > 0 and not operation.complete:
... retry_count -= 1
Expand All @@ -76,7 +79,7 @@ See: `Speech Asynchronous Recognize`_
Synchronous Recognition
-----------------------

The :meth:`~google.cloud.speech.Client.sync_recognize` method converts speech
The :meth:`~google.cloud.speech.Client.recognize` method converts speech
data to text and returns alternative text transcriptions.

This example uses ``language_code='en-GB'`` to better recognize a dialect from
Expand All @@ -88,8 +91,8 @@ Great Britain.
>>> client = speech.Client()
>>> sample = client.sample(source_uri='gs://my-bucket/recording.flac',
... encoding=speech.Encoding.FLAC,
... sample_rate=44100)
>>> results = sample.sync_recognize(
... sample_rate_hertz=44100)
>>> results = sample.recognize(
... language_code='en-GB', max_alternatives=2)
>>> for result in results:
... for alternative in result.alternatives:
Expand All @@ -111,9 +114,12 @@ Example of using the profanity filter.
>>> client = speech.Client()
>>> sample = client.sample(source_uri='gs://my-bucket/recording.flac',
... encoding=speech.Encoding.FLAC,
... sample_rate=44100)
>>> results = sample.sync_recognize(max_alternatives=1,
... profanity_filter=True)
... sample_rate_hertz=44100)
>>> results = sample.recognize(
... language_code='en-US',
... max_alternatives=1,
... profanity_filter=True,
... )
>>> for result in results:
... for alternative in result.alternatives:
... print('=' * 20)
Expand All @@ -133,10 +139,13 @@ words to the vocabulary of the recognizer.
>>> client = speech.Client()
>>> sample = client.sample(source_uri='gs://my-bucket/recording.flac',
... encoding=speech.Encoding.FLAC,
... sample_rate=44100)
... sample_rate_hertz=44100)
>>> hints = ['hi', 'good afternoon']
>>> results = sample.sync_recognize(max_alternatives=2,
... speech_context=hints)
>>> results = sample.recognize(
... language_code='en-US',
... max_alternatives=2,
... speech_context=hints,
... )
>>> for result in results:
... for alternative in result.alternatives:
... print('=' * 20)
Expand Down Expand Up @@ -165,8 +174,8 @@ speech data to possible text alternatives on the fly.
>>> with open('./hello.wav', 'rb') as stream:
... sample = client.sample(stream=stream,
... encoding=speech.Encoding.LINEAR16,
... sample_rate=16000)
... results = sample.streaming_recognize()
... sample_rate_hertz=16000)
... results = sample.streaming_recognize(language_code='en-US')
... for result in results:
... for alternative in result.alternatives:
... print('=' * 20)
Expand All @@ -192,8 +201,11 @@ See: `Single Utterance`_
>>> with open('./hello_pause_goodbye.wav', 'rb') as stream:
... sample = client.sample(stream=stream,
... encoding=speech.Encoding.LINEAR16,
... sample_rate=16000)
... results = sample.streaming_recognize(single_utterance=True)
... sample_rate_hertz=16000)
... results = sample.streaming_recognize(
... language_code='en-US',
... single_utterance=True,
... )
... for result in results:
... for alternative in result.alternatives:
... print('=' * 20)
Expand All @@ -214,7 +226,10 @@ If ``interim_results`` is set to :data:`True`, interim results
... sample = client.sample(stream=stream,
... encoding=speech.Encoding.LINEAR16,
... sample_rate=16000)
... results = sample.streaming_recognize(interim_results=True):
... results = sample.streaming_recognize(
... interim_results=True,
... language_code='en-US',
... )
... for result in results:
... for alternative in result.alternatives:
... print('=' * 20)
Expand Down
Loading