Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
more info on alternatives [(#1791)](GoogleCloudPlatform/python-docs-s…
Browse files Browse the repository at this point in the history
…amples#1791)

* more info on alternatives

* add comment
  • Loading branch information
dizcology authored and danoscarmike committed Sep 30, 2020
1 parent 0312b88 commit 9354c0f
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions samples/analyze/beta_snippets.py
Expand Up @@ -55,21 +55,27 @@ def speech_transcription(input_uri):
# There is only one annotation_result since only
# one video is processed.
annotation_results = result.annotation_results[0]
speech_transcription = annotation_results.speech_transcriptions[0]
alternative = speech_transcription.alternatives[0]

print('Transcript: {}'.format(alternative.transcript))
print('Confidence: {}\n'.format(alternative.confidence))

print('Word level information:')
for word_info in alternative.words:
word = word_info.word
start_time = word_info.start_time
end_time = word_info.end_time
print('\t{}s - {}s: {}'.format(
start_time.seconds + start_time.nanos * 1e-9,
end_time.seconds + end_time.nanos * 1e-9,
word))
for speech_transcription in annotation_results.speech_transcriptions:

# The number of alternatives for each transcription is limited by
# SpeechTranscriptionConfig.max_alternatives.
# Each alternative is a different possible transcription
# and has its own confidence score.
for alternative in speech_transcription.alternatives:
print('Alternative level information:')

print('Transcript: {}'.format(alternative.transcript))
print('Confidence: {}\n'.format(alternative.confidence))

print('Word level information:')
for word_info in alternative.words:
word = word_info.word
start_time = word_info.start_time
end_time = word_info.end_time
print('\t{}s - {}s: {}'.format(
start_time.seconds + start_time.nanos * 1e-9,
end_time.seconds + end_time.nanos * 1e-9,
word))
# [END video_speech_transcription_gcs_beta]


Expand Down

0 comments on commit 9354c0f

Please sign in to comment.