Skip to content

Commit 7a15ffc

Browse files
nnegreytseaver
authored andcommitted
Clarify passed arguments in speech examples. (googleapis#6857)
1 parent 26fd472 commit 7a15ffc

File tree

1 file changed

+35
-47
lines changed

1 file changed

+35
-47
lines changed

speech/docs/index.rst

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ See: `Speech Asynchronous Recognize`_
1919
2020
>>> from google.cloud import speech
2121
>>> client = speech.SpeechClient()
22-
>>> operation = client.long_running_recognize(
23-
... audio=speech.types.RecognitionAudio(
24-
... uri='gs://my-bucket/recording.flac',
25-
... ),
26-
... config=speech.types.RecognitionConfig(
27-
... encoding='LINEAR16',
28-
... language_code='en-US',
29-
... sample_rate_hertz=44100,
30-
... ),
31-
... )
22+
>>> audio = speech.types.RecognitionAudio(
23+
... uri='gs://my-bucket/recording.flac')
24+
>>> config = speech.types.RecognitionConfig(
25+
... encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
26+
... language_code='en-US',
27+
... sample_rate_hertz=44100)
28+
>>> operation = client.long_running_recognize(config=config, audio=audio)
3229
>>> op_result = operation.result()
3330
>>> for result in op_result.results:
3431
... for alternative in result.alternatives:
@@ -53,16 +50,13 @@ Great Britain.
5350
5451
>>> from google.cloud import speech
5552
>>> client = speech.SpeechClient()
56-
>>> results = client.recognize(
57-
... audio=speech.types.RecognitionAudio(
58-
... uri='gs://my-bucket/recording.flac',
59-
... ),
60-
... config=speech.types.RecognitionConfig(
61-
... encoding='LINEAR16',
62-
... language_code='en-US',
63-
... sample_rate_hertz=44100,
64-
... ),
65-
... )
53+
>>> audio = speech.types.RecognitionAudio(
54+
... uri='gs://my-bucket/recording.flac')
55+
>>> config = speech.types.RecognitionConfig(
56+
... encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
57+
... language_code='en-US',
58+
... sample_rate_hertz=44100)
59+
>>> results = client.recognize(config=config, audio=audio)
6660
>>> for result in results:
6761
... for alternative in result.alternatives:
6862
... print('=' * 20)
@@ -81,17 +75,14 @@ Example of using the profanity filter.
8175
8276
>>> from google.cloud import speech
8377
>>> client = speech.SpeechClient()
84-
>>> results = client.recognize(
85-
... audio=speech.types.RecognitionAudio(
86-
... uri='gs://my-bucket/recording.flac',
87-
... ),
88-
... config=speech.types.RecognitionConfig(
89-
... encoding='LINEAR16',
90-
... language_code='en-US',
91-
... profanity_filter=True,
92-
... sample_rate_hertz=44100,
93-
... ),
94-
... )
78+
>>> audio = speech.types.RecognitionAudio(
79+
... uri='gs://my-bucket/recording.flac')
80+
>>> config = speech.types.RecognitionConfig(
81+
... encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
82+
... language_code='en-US',
83+
... sample_rate_hertz=44100,
84+
... profanity_filter=True)
85+
>>> results = client.recognize(config=config, audio=audio)
9586
>>> for result in results:
9687
... for alternative in result.alternatives:
9788
... print('=' * 20)
@@ -110,19 +101,16 @@ words to the vocabulary of the recognizer.
110101
>>> from google.cloud import speech
111102
>>> from google.cloud import speech
112103
>>> client = speech.SpeechClient()
113-
>>> results = client.recognize(
114-
... audio=speech.types.RecognitionAudio(
115-
... uri='gs://my-bucket/recording.flac',
116-
... ),
117-
... config=speech.types.RecognitionConfig(
118-
... encoding='LINEAR16',
119-
... language_code='en-US',
120-
... sample_rate_hertz=44100,
121-
... speech_contexts=[speech.types.SpeechContext(
122-
... phrases=['hi', 'good afternoon'],
123-
... )],
124-
... ),
125-
... )
104+
>>> audio = speech.types.RecognitionAudio(
105+
... uri='gs://my-bucket/recording.flac')
106+
>>> config = speech.types.RecognitionConfig(
107+
... encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
108+
... language_code='en-US',
109+
... sample_rate_hertz=44100,
110+
... speech_contexts=[speech.types.SpeechContext(
111+
... phrases=['hi', 'good afternoon'],
112+
... )])
113+
>>> results = client.recognize(config=config, audio=audio)
126114
>>> for result in results:
127115
... for alternative in result.alternatives:
128116
... print('=' * 20)
@@ -150,7 +138,7 @@ speech data to possible text alternatives on the fly.
150138
>>> from google.cloud import speech
151139
>>> client = speech.SpeechClient()
152140
>>> config = speech.types.RecognitionConfig(
153-
... encoding='LINEAR16',
141+
... encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
154142
... language_code='en-US',
155143
... sample_rate_hertz=44100,
156144
... )
@@ -188,7 +176,7 @@ See: `Single Utterance`_
188176
>>> from google.cloud import speech
189177
>>> client = speech.SpeechClient()
190178
>>> config = speech.types.RecognitionConfig(
191-
... encoding='LINEAR16',
179+
... encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
192180
... language_code='en-US',
193181
... sample_rate_hertz=44100,
194182
... )
@@ -226,7 +214,7 @@ If ``interim_results`` is set to :data:`True`, interim results
226214
>>> from google.cloud import speech
227215
>>> client = speech.SpeechClient()
228216
>>> config = speech.types.RecognitionConfig(
229-
... encoding='LINEAR16',
217+
... encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
230218
... language_code='en-US',
231219
... sample_rate_hertz=44100,
232220
... )

0 commit comments

Comments
 (0)