File tree 3 files changed +16
-4
lines changed
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):
51
51
# [START migration_sync_response]
52
52
response = client .recognize (config , audio )
53
53
# [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.
55
56
for result in response .results :
57
+ # The first alternative is the most likely one for this portion.
56
58
print ('Transcript: {}' .format (result .alternatives [0 ].transcript ))
57
59
# [END migration_sync_response]
58
60
# [END def_transcribe_file]
@@ -75,8 +77,10 @@ def transcribe_gcs(gcs_uri):
75
77
# [END migration_audio_config_gcs]
76
78
77
79
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.
79
82
for result in response .results :
83
+ # The first alternative is the most likely one for this portion.
80
84
print ('Transcript: {}' .format (result .alternatives [0 ].transcript ))
81
85
# [END def_transcribe_gcs]
82
86
Original file line number Diff line number Diff line change @@ -51,8 +51,10 @@ def transcribe_file(speech_file):
51
51
print ('Waiting for operation to complete...' )
52
52
response = operation .result (timeout = 90 )
53
53
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.
55
56
for result in response .results :
57
+ # The first alternative is the most likely one for this portion.
56
58
print ('Transcript: {}' .format (result .alternatives [0 ].transcript ))
57
59
print ('Confidence: {}' .format (result .alternatives [0 ].confidence ))
58
60
# [END migration_async_response]
@@ -78,8 +80,10 @@ def transcribe_gcs(gcs_uri):
78
80
print ('Waiting for operation to complete...' )
79
81
response = operation .result (timeout = 90 )
80
82
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.
82
85
for result in response .results :
86
+ # The first alternative is the most likely one for this portion.
83
87
print ('Transcript: {}' .format (result .alternatives [0 ].transcript ))
84
88
print ('Confidence: {}' .format (result .alternatives [0 ].confidence ))
85
89
# [END def_transcribe_gcs]
Original file line number Diff line number Diff line change @@ -55,10 +55,14 @@ def transcribe_streaming(stream_file):
55
55
# [END migration_streaming_request]
56
56
57
57
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.
58
61
for result in response .results :
59
62
print ('Finished: {}' .format (result .is_final ))
60
63
print ('Stability: {}' .format (result .stability ))
61
64
alternatives = result .alternatives
65
+ # The alternatives are ordered from most likely to least.
62
66
for alternative in alternatives :
63
67
print ('Confidence: {}' .format (alternative .confidence ))
64
68
print ('Transcript: {}' .format (alternative .transcript ))
You can’t perform that action at this time.
0 commit comments