@@ -55,21 +55,27 @@ def speech_transcription(input_uri):
55
55
# There is only one annotation_result since only
56
56
# one video is processed.
57
57
annotation_results = result .annotation_results [0 ]
58
- speech_transcription = annotation_results .speech_transcriptions [0 ]
59
- alternative = speech_transcription .alternatives [0 ]
60
-
61
- print ('Transcript: {}' .format (alternative .transcript ))
62
- print ('Confidence: {}\n ' .format (alternative .confidence ))
63
-
64
- print ('Word level information:' )
65
- for word_info in alternative .words :
66
- word = word_info .word
67
- start_time = word_info .start_time
68
- end_time = word_info .end_time
69
- print ('\t {}s - {}s: {}' .format (
70
- start_time .seconds + start_time .nanos * 1e-9 ,
71
- end_time .seconds + end_time .nanos * 1e-9 ,
72
- word ))
58
+ for speech_transcription in annotation_results .speech_transcriptions :
59
+
60
+ # The number of alternatives for each transcription is limited by
61
+ # SpeechTranscriptionConfig.max_alternatives.
62
+ # Each alternative is a different possible transcription
63
+ # and has its own confidence score.
64
+ for alternative in speech_transcription .alternatives :
65
+ print ('Alternative level information:' )
66
+
67
+ print ('Transcript: {}' .format (alternative .transcript ))
68
+ print ('Confidence: {}\n ' .format (alternative .confidence ))
69
+
70
+ print ('Word level information:' )
71
+ for word_info in alternative .words :
72
+ word = word_info .word
73
+ start_time = word_info .start_time
74
+ end_time = word_info .end_time
75
+ print ('\t {}s - {}s: {}' .format (
76
+ start_time .seconds + start_time .nanos * 1e-9 ,
77
+ end_time .seconds + end_time .nanos * 1e-9 ,
78
+ word ))
73
79
# [END video_speech_transcription_gcs_beta]
74
80
75
81
0 commit comments