@@ -83,5 +83,73 @@ data to text and returns alternative text transcriptons.
8383 transcript: Hello, this is one test
8484 confidence: 0
8585
86+
87+ Streaming Recognition
88+ ---------------------
89+
90+ The :meth: `~google.cloud.speech.Client.stream_recognize ` method converts speech
91+ data to possible text alternatives on the fly.
92+
93+ .. note ::
94+ Streaming recognition requests are limited to 1 minute of audio.
95+
96+ See: https://cloud.google.com/speech/limits#content
97+
98+ .. code-block :: python
99+
100+ >> > from google.cloud import speech
101+ >> > client = speech.Client()
102+ >> > results = client.stream_recognize(' hello.flac' , ' FLAC' , 44100 )
103+ >> > results[0 ].is_final
104+ False
105+ >> > results[2 ].is_final
106+ True
107+ >> > results[2 ].alternatives[0 ].transcript
108+ hello
109+ >> > results[2 ].alternatives[0 ].confidence
110+ 0.96976006031
111+
112+ For continuous speech containing more than one word, the ``single_utterance ``
113+ option should be disabled.
114+
115+ See: `Single Utterance `_
116+
117+ .. code-block :: python
118+
119+ >> > results = client.stream_recognize(' hello.flac' , ' FLAC' , 44100 ,
120+ ... single_utterance = False )
121+
122+
123+ If you would like interim results to be returned as well as the final results,
124+ you can set the ``interim_results `` option to ``True ``.
125+
126+ .. code-block :: python
127+
128+ >> > results = client.stream_recognize(' hello.flac' , ' FLAC' , 44100 ,
129+ ... interim_results = True )
130+ >> > print results
131+ [{
132+ alternatives: {
133+ transcript: ' how'
134+ },
135+ stability: 0.00999999977648
136+ },
137+ {
138+ alternatives: {
139+ transcript: ' hello'
140+ }
141+ stability: 0.00999999977648
142+ },
143+ {
144+ alternatives: {
145+ transcript: ' hello'
146+ confidence: 0.96976006031
147+ }
148+ is_final: true
149+ }
150+ ]
151+
152+
153+ .. _Single Utterance : https://cloud.google.com/speech/reference/rpc/google.cloud.speech.v1beta1#streamingrecognitionconfig
86154.. _sync_recognize : https://cloud.google.com/speech/reference/rest/v1beta1/speech/syncrecognize
87155.. _Speech Asynchronous Recognize : https://cloud.google.com/speech/reference/rest/v1beta1/speech/asyncrecognize
0 commit comments