@@ -157,24 +157,47 @@ data to possible text alternatives on the fly.
157157
158158 See: https://cloud.google.com/speech/limits#content
159159
160+ .. code-block :: python
161+
160162 >> > import io
161163 >> > from google.cloud import speech
162164 >> > from google.cloud.speech.encoding import Encoding
163165 >> > client = speech.Client()
164166 >> > with io.open(' ./hello.wav' , ' rb' ) as stream:
165167 >> > sample = client.sample(stream = stream, encoding = Encoding.LINEAR16 ,
166168 ... sample_rate = 16000 )
167- >>> stream_container = client.stream_recognize(sample)
168- >>> print (stream_container)
169- <google.cloud.speech.streaming.container.StreamingResponseContainer object at 0x10538ee10>
170- >>> print (stream_container.responses)
171- {0: <google.cloud.speech.streaming.response.StreamingSpeechResponse object at 0x10f9ac9d0>}
172- >>> print (stream_container.responses[0 ].results[0 ].alternatives[0 ].confidence)
173- 0.698092460632
174- >>> print (stream_container.is_finished)
169+ >> > for response in client.stream_recognize(sample):
170+ ... print (response.transcript)
171+ hello
172+ ... print (response.is_final)
175173 True
176- >>> print stream_container.get_full_text()
174+
175+
176+ By setting ``interim_results `` to true, interim results (tentative hypotheses)
177+ may be returned as they become available (these interim results are indicated
178+ with the is_final=false flag). If false or omitted, only is_final=true
179+ result(s) are returned.
180+
181+ .. code-block :: python
182+
183+ >> > import io
184+ >> > from google.cloud import speech
185+ >> > from google.cloud.speech.encoding import Encoding
186+ >> > client = speech.Client()
187+ >> > with io.open(' ./hello.wav' , ' rb' ) as stream:
188+ >> > sample = client.sample(stream = stream, encoding = Encoding.LINEAR16 ,
189+ ... sample_rate = 16000 )
190+ >> > for response in client.stream_recognize(sample,
191+ ... interim_results = True ):
192+ ... print (response.transcript)
193+ hell
194+ ... print (response.is_final)
195+ False
196+ ... print (response.transcript)
177197 hello
198+ ... print (response.is_final)
199+ True
200+
178201
179202 By default the recognizer will perform continuous recognition
180203(continuing to process audio even if the user pauses speaking) until the client
@@ -195,32 +218,6 @@ See: `Single Utterance`_
195218 >> > print (stream_container.get_full_text())
196219 hello
197220
198-
199- If ``interim_results `` is set to ``True ``, interim results
200- (tentative hypotheses) may be returned as they become available.
201-
202- .. code-block :: python
203-
204- >> > with io.open(' ./hello_pause_goodbye.wav' , ' rb' ) as stream:
205- >> > sample = client.sample(stream = stream, encoding = Encoding.LINEAR16 ,
206- ... sample_rate = 16000 )
207- >> > stream_container = client.stream_recognize(sample,
208- ... interim_results = True )
209- >> > print (stream_container.get_full_text())
210- hello
211-
212- >> > sample = client.sample(source_uri = ' gs://my-bucket/recording.flac' ,
213- ... encoding = Encoding.FLAC ,
214- ... sample_rate = 44100 )
215- >> > results = client.stream_recognize(sample, interim_results = True )
216- >> > print (stream_container.responses[0 ].results[0 ].alternatives[0 ].transcript)
217- how
218- print (stream_container.responses[1 ].results[0 ].alternatives[0 ].transcript)
219- hello
220- >> > print (stream_container.responses[1 ].results[2 ].is_final)
221- True
222-
223-
224221 .. _Single Utterance : https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#streamingrecognitionconfig
225222.. _sync_recognize : https://cloud.google.com/speech/reference/rest/v1beta1/speech/syncrecognize
226223.. _Speech Asynchronous Recognize : https://cloud.google.com/speech/reference/rest/v1beta1/speech/asyncrecognize
0 commit comments