Skip to content

Commit 34933c6

Browse files
authored
more info on alternatives (#1791)
* more info on alternatives * add comment
1 parent bfd5d07 commit 34933c6

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

video/cloud-client/analyze/beta_snippets.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,27 @@ def speech_transcription(input_uri):
5555
# There is only one annotation_result since only
5656
# one video is processed.
5757
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))
7379
# [END video_speech_transcription_gcs_beta]
7480

7581

0 commit comments

Comments
 (0)