File tree Expand file tree Collapse file tree 8 files changed +45
-17
lines changed Expand file tree Collapse file tree 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:
136136 -h, --help show this help message and exit
137137
138138
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+
139164
140165
141166 The client library
Original file line number Diff line number Diff line change @@ -22,5 +22,8 @@ samples:
2222- name: Transcribe async
2323 file: transcribe_async.py
2424 show_help: true
25+ - name: Transcribe Streaming
26+ file: transcribe_streaming.py
27+ show_help: true
2528
2629cloud_client_library: true
Original file line number Diff line number Diff line change @@ -35,14 +35,14 @@ def run_quickstart():
3535 # Loads the audio into memory
3636 with io .open (file_name , 'rb' ) as audio_file :
3737 content = audio_file .read ()
38- audio_sample = speech_client .sample (
38+ sample = speech_client .sample (
3939 content ,
4040 source_uri = None ,
4141 encoding = 'LINEAR16' ,
42- sample_rate = 16000 )
42+ sample_rate_hertz = 16000 )
4343
4444 # Detects speech in the audio file
45- alternatives = speech_client . speech_api . sync_recognize ( audio_sample )
45+ alternatives = sample . recognize ( 'en-US' )
4646
4747 for alternative in alternatives :
4848 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):
3939 content = content ,
4040 source_uri = None ,
4141 encoding = 'LINEAR16' ,
42- sample_rate = 16000 )
42+ sample_rate_hertz = 16000 )
4343
44- alternatives = speech_client . speech_api . sync_recognize ( audio_sample )
44+ alternatives = audio_sample . recognize ( 'en-US' )
4545 for alternative in alternatives :
4646 print ('Transcript: {}' .format (alternative .transcript ))
4747
@@ -55,9 +55,9 @@ def transcribe_gcs(gcs_uri):
5555 content = None ,
5656 source_uri = gcs_uri ,
5757 encoding = 'FLAC' ,
58- sample_rate = 16000 )
58+ sample_rate_hertz = 16000 )
5959
60- alternatives = speech_client . speech_api . sync_recognize ( audio_sample )
60+ alternatives = audio_sample . recognize ( 'en-US' )
6161 for alternative in alternatives :
6262 print ('Transcript: {}' .format (alternative .transcript ))
6363
Original file line number Diff line number Diff line change 1919
2020Example usage:
2121 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
2323"""
2424
2525import argparse
@@ -38,9 +38,9 @@ def transcribe_file(speech_file):
3838 content ,
3939 source_uri = None ,
4040 encoding = 'LINEAR16' ,
41- sample_rate = 16000 )
41+ sample_rate_hertz = 16000 )
4242
43- operation = speech_client . speech_api . async_recognize ( audio_sample )
43+ operation = audio_sample . long_running_recognize ( 'en-US' )
4444
4545 retry_count = 100
4646 while retry_count > 0 and not operation .complete :
@@ -67,10 +67,10 @@ def transcribe_gcs(gcs_uri):
6767 audio_sample = speech_client .sample (
6868 content = None ,
6969 source_uri = gcs_uri ,
70- encoding = 'FLAC ' ,
71- sample_rate = 16000 )
70+ encoding = 'LINEAR16 ' ,
71+ sample_rate_hertz = 16000 )
7272
73- operation = speech_client . speech_api . async_recognize ( audio_sample )
73+ operation = audio_sample . long_running_recognize ( 'en-US' )
7474
7575 retry_count = 100
7676 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):
2929
3030def test_transcribe_gcs (capsys ):
3131 transcribe_async .transcribe_gcs (
32- 'gs://python-docs-samples-tests/speech/audio.flac ' )
32+ 'gs://python-docs-samples-tests/speech/audio.raw ' )
3333 out , err = capsys .readouterr ()
3434
3535 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):
3535 audio_sample = speech_client .sample (
3636 stream = audio_file ,
3737 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' )
4040
4141 for alternative in alternatives :
4242 print ('Finished: {}' .format (alternative .is_final ))
You can’t perform that action at this time.
0 commit comments