@@ -34,10 +34,10 @@ create an instance of :class:`~google.cloud.speech.client.Client`.
34
34
Asynchronous Recognition
35
35
------------------------
36
36
37
- The :meth: `~google.cloud.speech.Client.async_recognize ` sends audio data to the
38
- Speech API and initiates a Long Running Operation. Using this operation, you
39
- can periodically poll for recognition results. Use asynchronous requests for
40
- audio data of any duration up to 80 minutes.
37
+ The :meth: `~google.cloud.speech.Client.long_running_recognize ` sends audio
38
+ data to the Speech API and initiates a Long Running Operation. Using this
39
+ operation, you can periodically poll for recognition results. Use asynchronous
40
+ requests for audio data of any duration up to 80 minutes.
41
41
42
42
.. note ::
43
43
@@ -54,8 +54,11 @@ See: `Speech Asynchronous Recognize`_
54
54
>> > client = speech.Client()
55
55
>> > sample = client.sample(source_uri = ' gs://my-bucket/recording.flac' ,
56
56
... encoding = speech.Encoding.LINEAR16 ,
57
- ... sample_rate = 44100 )
58
- >> > operation = sample.async_recognize(max_alternatives = 2 )
57
+ ... sample_rate_hertz = 44100 )
58
+ >> > operation = sample.long_running_recognize(
59
+ ... language_code = ' en-US' ,
60
+ ... max_alternatives = 2 ,
61
+ ... )
59
62
>> > retry_count = 100
60
63
>> > while retry_count > 0 and not operation.complete:
61
64
... retry_count -= 1
@@ -76,7 +79,7 @@ See: `Speech Asynchronous Recognize`_
76
79
Synchronous Recognition
77
80
-----------------------
78
81
79
- The :meth: `~google.cloud.speech.Client.sync_recognize ` method converts speech
82
+ The :meth: `~google.cloud.speech.Client.recognize ` method converts speech
80
83
data to text and returns alternative text transcriptions.
81
84
82
85
This example uses ``language_code='en-GB' `` to better recognize a dialect from
@@ -88,8 +91,8 @@ Great Britain.
88
91
>> > client = speech.Client()
89
92
>> > sample = client.sample(source_uri = ' gs://my-bucket/recording.flac' ,
90
93
... encoding = speech.Encoding.FLAC ,
91
- ... sample_rate = 44100 )
92
- >> > results = sample.sync_recognize (
94
+ ... sample_rate_hertz = 44100 )
95
+ >> > results = sample.recognize (
93
96
... language_code = ' en-GB' , max_alternatives = 2 )
94
97
>> > for result in results:
95
98
... for alternative in result.alternatives:
@@ -111,9 +114,12 @@ Example of using the profanity filter.
111
114
>> > client = speech.Client()
112
115
>> > sample = client.sample(source_uri = ' gs://my-bucket/recording.flac' ,
113
116
... encoding = speech.Encoding.FLAC ,
114
- ... sample_rate = 44100 )
115
- >> > results = sample.sync_recognize(max_alternatives = 1 ,
116
- ... profanity_filter = True )
117
+ ... sample_rate_hertz = 44100 )
118
+ >> > results = sample.recognize(
119
+ ... language_code = ' en-US' ,
120
+ ... max_alternatives = 1 ,
121
+ ... profanity_filter = True ,
122
+ ... )
117
123
>> > for result in results:
118
124
... for alternative in result.alternatives:
119
125
... print (' =' * 20 )
@@ -133,10 +139,13 @@ words to the vocabulary of the recognizer.
133
139
>> > client = speech.Client()
134
140
>> > sample = client.sample(source_uri = ' gs://my-bucket/recording.flac' ,
135
141
... encoding = speech.Encoding.FLAC ,
136
- ... sample_rate = 44100 )
142
+ ... sample_rate_hertz = 44100 )
137
143
>> > hints = [' hi' , ' good afternoon' ]
138
- >> > results = sample.sync_recognize(max_alternatives = 2 ,
139
- ... speech_context = hints)
144
+ >> > results = sample.recognize(
145
+ ... language_code = ' en-US' ,
146
+ ... max_alternatives = 2 ,
147
+ ... speech_context = hints,
148
+ ... )
140
149
>> > for result in results:
141
150
... for alternative in result.alternatives:
142
151
... print (' =' * 20 )
@@ -165,8 +174,8 @@ speech data to possible text alternatives on the fly.
165
174
>> > with open (' ./hello.wav' , ' rb' ) as stream:
166
175
... sample = client.sample(stream = stream,
167
176
... encoding = speech.Encoding.LINEAR16 ,
168
- ... sample_rate = 16000 )
169
- ... results = sample.streaming_recognize()
177
+ ... sample_rate_hertz = 16000 )
178
+ ... results = sample.streaming_recognize(language_code = ' en-US ' )
170
179
... for result in results:
171
180
... for alternative in result.alternatives:
172
181
... print (' =' * 20 )
@@ -192,8 +201,11 @@ See: `Single Utterance`_
192
201
>> > with open (' ./hello_pause_goodbye.wav' , ' rb' ) as stream:
193
202
... sample = client.sample(stream = stream,
194
203
... encoding = speech.Encoding.LINEAR16 ,
195
- ... sample_rate = 16000 )
196
- ... results = sample.streaming_recognize(single_utterance = True )
204
+ ... sample_rate_hertz = 16000 )
205
+ ... results = sample.streaming_recognize(
206
+ ... language_code = ' en-US' ,
207
+ ... single_utterance = True ,
208
+ ... )
197
209
... for result in results:
198
210
... for alternative in result.alternatives:
199
211
... print (' =' * 20 )
@@ -214,7 +226,10 @@ If ``interim_results`` is set to :data:`True`, interim results
214
226
... sample = client.sample(stream = stream,
215
227
... encoding = speech.Encoding.LINEAR16 ,
216
228
... sample_rate = 16000 )
217
- ... results = sample.streaming_recognize(interim_results = True ):
229
+ ... results = sample.streaming_recognize(
230
+ ... interim_results = True ,
231
+ ... language_code = ' en-US' ,
232
+ ... )
218
233
... for result in results:
219
234
... for alternative in result.alternatives:
220
235
... print (' =' * 20 )
0 commit comments