File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed
Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -51,8 +51,10 @@ def transcribe_file(speech_file):
5151 # [START migration_sync_response]
5252 response = client .recognize (config , audio )
5353 # [END migration_sync_request]
54- # Print the first alternative of all the consecutive results.
54+ # Each result is for a consecutive portion of the audio. Iterate through
55+ # them to get the transcripts for the entire audio file.
5556 for result in response .results :
57+ # The first alternative is the most likely one for this portion.
5658 print ('Transcript: {}' .format (result .alternatives [0 ].transcript ))
5759 # [END migration_sync_response]
5860# [END def_transcribe_file]
@@ -75,8 +77,10 @@ def transcribe_gcs(gcs_uri):
7577 # [END migration_audio_config_gcs]
7678
7779 response = client .recognize (config , audio )
78- # Print the first alternative of all the consecutive results.
80+ # Each result is for a consecutive portion of the audio. Iterate through
81+ # them to get the transcripts for the entire audio file.
7982 for result in response .results :
83+ # The first alternative is the most likely one for this portion.
8084 print ('Transcript: {}' .format (result .alternatives [0 ].transcript ))
8185# [END def_transcribe_gcs]
8286
Original file line number Diff line number Diff line change @@ -51,8 +51,10 @@ def transcribe_file(speech_file):
5151 print ('Waiting for operation to complete...' )
5252 response = operation .result (timeout = 90 )
5353
54- # Print the first alternative of all the consecutive results.
54+ # Each result is for a consecutive portion of the audio. Iterate through
55+ # them to get the transcripts for the entire audio file.
5556 for result in response .results :
57+ # The first alternative is the most likely one for this portion.
5658 print ('Transcript: {}' .format (result .alternatives [0 ].transcript ))
5759 print ('Confidence: {}' .format (result .alternatives [0 ].confidence ))
5860 # [END migration_async_response]
@@ -78,8 +80,10 @@ def transcribe_gcs(gcs_uri):
7880 print ('Waiting for operation to complete...' )
7981 response = operation .result (timeout = 90 )
8082
81- # Print the first alternative of all the consecutive results.
83+ # Each result is for a consecutive portion of the audio. Iterate through
84+ # them to get the transcripts for the entire audio file.
8285 for result in response .results :
86+ # The first alternative is the most likely one for this portion.
8387 print ('Transcript: {}' .format (result .alternatives [0 ].transcript ))
8488 print ('Confidence: {}' .format (result .alternatives [0 ].confidence ))
8589# [END def_transcribe_gcs]
Original file line number Diff line number Diff line change @@ -55,10 +55,14 @@ def transcribe_streaming(stream_file):
5555 # [END migration_streaming_request]
5656
5757 for response in responses :
58+ # Once the transcription has settled, the first result will contain the
59+ # is_final result. The other results will be for subsequent portions of
60+ # the audio.
5861 for result in response .results :
5962 print ('Finished: {}' .format (result .is_final ))
6063 print ('Stability: {}' .format (result .stability ))
6164 alternatives = result .alternatives
65+ # The alternatives are ordered from most likely to least.
6266 for alternative in alternatives :
6367 print ('Confidence: {}' .format (alternative .confidence ))
6468 print ('Transcript: {}' .format (alternative .transcript ))
You can’t perform that action at this time.
0 commit comments