File tree 8 files changed +45
-17
lines changed
google-cloud-speech/samples/snippets
8 files changed +45
-17
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,31 @@ To run this sample:
136
136
-h, --help show this help message and exit
137
137
138
138
139
+ Transcribe Streaming
140
+ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
141
+
142
+
143
+
144
+ To run this sample:
145
+
146
+ .. code-block :: bash
147
+
148
+ $ python transcribe_streaming.py
149
+
150
+ usage: transcribe_streaming.py [-h] stream
151
+
152
+ Google Cloud Speech API sample application using the streaming API.
153
+
154
+ Example usage:
155
+ python transcribe_streaming.py resources/audio.raw
156
+
157
+ positional arguments:
158
+ stream File to stream to the API
159
+
160
+ optional arguments:
161
+ -h, --help show this help message and exit
162
+
163
+
139
164
140
165
141
166
The client library
Original file line number Diff line number Diff line change @@ -22,5 +22,8 @@ samples:
22
22
- name: Transcribe async
23
23
file: transcribe_async.py
24
24
show_help: true
25
+ - name: Transcribe Streaming
26
+ file: transcribe_streaming.py
27
+ show_help: true
25
28
26
29
cloud_client_library: true
Original file line number Diff line number Diff line change @@ -35,14 +35,14 @@ def run_quickstart():
35
35
# Loads the audio into memory
36
36
with io .open (file_name , 'rb' ) as audio_file :
37
37
content = audio_file .read ()
38
- audio_sample = speech_client .sample (
38
+ sample = speech_client .sample (
39
39
content ,
40
40
source_uri = None ,
41
41
encoding = 'LINEAR16' ,
42
- sample_rate = 16000 )
42
+ sample_rate_hertz = 16000 )
43
43
44
44
# Detects speech in the audio file
45
- alternatives = speech_client . speech_api . sync_recognize ( audio_sample )
45
+ alternatives = sample . recognize ( 'en-US' )
46
46
47
47
for alternative in alternatives :
48
48
print ('Transcript: {}' .format (alternative .transcript ))
Original file line number Diff line number Diff line change 1
- google-cloud-speech == 0.23 .0
1
+ google-cloud-speech == 0.25 .0
Original file line number Diff line number Diff line change @@ -39,9 +39,9 @@ def transcribe_file(speech_file):
39
39
content = content ,
40
40
source_uri = None ,
41
41
encoding = 'LINEAR16' ,
42
- sample_rate = 16000 )
42
+ sample_rate_hertz = 16000 )
43
43
44
- alternatives = speech_client . speech_api . sync_recognize ( audio_sample )
44
+ alternatives = audio_sample . recognize ( 'en-US' )
45
45
for alternative in alternatives :
46
46
print ('Transcript: {}' .format (alternative .transcript ))
47
47
@@ -55,9 +55,9 @@ def transcribe_gcs(gcs_uri):
55
55
content = None ,
56
56
source_uri = gcs_uri ,
57
57
encoding = 'FLAC' ,
58
- sample_rate = 16000 )
58
+ sample_rate_hertz = 16000 )
59
59
60
- alternatives = speech_client . speech_api . sync_recognize ( audio_sample )
60
+ alternatives = audio_sample . recognize ( 'en-US' )
61
61
for alternative in alternatives :
62
62
print ('Transcript: {}' .format (alternative .transcript ))
63
63
Original file line number Diff line number Diff line change 19
19
20
20
Example usage:
21
21
python transcribe_async.py resources/audio.raw
22
- python transcribe_async.py gs://cloud-samples-tests/speech/brooklyn.flac
22
+ python transcribe_async.py gs://cloud-samples-tests/speech/brooklyn.raw
23
23
"""
24
24
25
25
import argparse
@@ -38,9 +38,9 @@ def transcribe_file(speech_file):
38
38
content ,
39
39
source_uri = None ,
40
40
encoding = 'LINEAR16' ,
41
- sample_rate = 16000 )
41
+ sample_rate_hertz = 16000 )
42
42
43
- operation = speech_client . speech_api . async_recognize ( audio_sample )
43
+ operation = audio_sample . long_running_recognize ( 'en-US' )
44
44
45
45
retry_count = 100
46
46
while retry_count > 0 and not operation .complete :
@@ -67,10 +67,10 @@ def transcribe_gcs(gcs_uri):
67
67
audio_sample = speech_client .sample (
68
68
content = None ,
69
69
source_uri = gcs_uri ,
70
- encoding = 'FLAC ' ,
71
- sample_rate = 16000 )
70
+ encoding = 'LINEAR16 ' ,
71
+ sample_rate_hertz = 16000 )
72
72
73
- operation = speech_client . speech_api . async_recognize ( audio_sample )
73
+ operation = audio_sample . long_running_recognize ( 'en-US' )
74
74
75
75
retry_count = 100
76
76
while retry_count > 0 and not operation .complete :
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ def test_transcribe(capsys):
29
29
30
30
def test_transcribe_gcs (capsys ):
31
31
transcribe_async .transcribe_gcs (
32
- 'gs://python-docs-samples-tests/speech/audio.flac ' )
32
+ 'gs://python-docs-samples-tests/speech/audio.raw ' )
33
33
out , err = capsys .readouterr ()
34
34
35
35
assert re .search (r'how old is the Brooklyn Bridge' , out , re .DOTALL | re .I )
Original file line number Diff line number Diff line change @@ -35,8 +35,8 @@ def transcribe_streaming(stream_file):
35
35
audio_sample = speech_client .sample (
36
36
stream = audio_file ,
37
37
encoding = speech .encoding .Encoding .LINEAR16 ,
38
- sample_rate = 16000 )
39
- alternatives = audio_sample .streaming_recognize ()
38
+ sample_rate_hertz = 16000 )
39
+ alternatives = audio_sample .streaming_recognize ('en-US' )
40
40
41
41
for alternative in alternatives :
42
42
print ('Finished: {}' .format (alternative .is_final ))
You can’t perform that action at this time.
0 commit comments