Skip to content

Commit

Permalink
Speech: clarify comments. [(#1278)](#1278)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerjou authored and pull[bot] committed Apr 24, 2023
1 parent 6505797 commit 2129bde
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions speech/snippets/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ def transcribe_file(speech_file):
# [START migration_sync_response]
response = client.recognize(config, audio)
# [END migration_sync_request]
# Print the first alternative of all the consecutive results.
# Each result is for a consecutive portion of the audio. Iterate through
# them to get the transcripts for the entire audio file.
for result in response.results:
# The first alternative is the most likely one for this portion.
print('Transcript: {}'.format(result.alternatives[0].transcript))
# [END migration_sync_response]
# [END def_transcribe_file]
Expand All @@ -75,8 +77,10 @@ def transcribe_gcs(gcs_uri):
# [END migration_audio_config_gcs]

response = client.recognize(config, audio)
# Print the first alternative of all the consecutive results.
# Each result is for a consecutive portion of the audio. Iterate through
# them to get the transcripts for the entire audio file.
for result in response.results:
# The first alternative is the most likely one for this portion.
print('Transcript: {}'.format(result.alternatives[0].transcript))
# [END def_transcribe_gcs]

Expand Down
8 changes: 6 additions & 2 deletions speech/snippets/transcribe_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ def transcribe_file(speech_file):
print('Waiting for operation to complete...')
response = operation.result(timeout=90)

# Print the first alternative of all the consecutive results.
# Each result is for a consecutive portion of the audio. Iterate through
# them to get the transcripts for the entire audio file.
for result in response.results:
# The first alternative is the most likely one for this portion.
print('Transcript: {}'.format(result.alternatives[0].transcript))
print('Confidence: {}'.format(result.alternatives[0].confidence))
# [END migration_async_response]
Expand All @@ -78,8 +80,10 @@ def transcribe_gcs(gcs_uri):
print('Waiting for operation to complete...')
response = operation.result(timeout=90)

# Print the first alternative of all the consecutive results.
# Each result is for a consecutive portion of the audio. Iterate through
# them to get the transcripts for the entire audio file.
for result in response.results:
# The first alternative is the most likely one for this portion.
print('Transcript: {}'.format(result.alternatives[0].transcript))
print('Confidence: {}'.format(result.alternatives[0].confidence))
# [END def_transcribe_gcs]
Expand Down
4 changes: 4 additions & 0 deletions speech/snippets/transcribe_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ def transcribe_streaming(stream_file):
# [END migration_streaming_request]

for response in responses:
# Once the transcription has settled, the first result will contain the
# is_final result. The other results will be for subsequent portions of
# the audio.
for result in response.results:
print('Finished: {}'.format(result.is_final))
print('Stability: {}'.format(result.stability))
alternatives = result.alternatives
# The alternatives are ordered from most likely to least.
for alternative in alternatives:
print('Confidence: {}'.format(alternative.confidence))
print('Transcript: {}'.format(alternative.transcript))
Expand Down

0 comments on commit 2129bde

Please sign in to comment.