Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cfa07e8

Browse filesBrowse files
authored
Print all results, not all alternatives (GoogleCloudPlatform#1098)
1 parent 92d6468 commit cfa07e8
Copy full SHA for cfa07e8

File tree

Expand file treeCollapse file tree

4 files changed

+23
-24
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+23
-24
lines changed

‎speech/cloud-client/transcribe.py

Copy file name to clipboardExpand all lines: speech/cloud-client/transcribe.py
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ def transcribe_file(speech_file):
5151
# [START migration_sync_response]
5252
response = client.recognize(config, audio)
5353
# [END migration_sync_request]
54-
alternatives = response.results[0].alternatives
55-
56-
for alternative in alternatives:
57-
print('Transcript: {}'.format(alternative.transcript))
54+
# Print the first alternative of all the consecutive results.
55+
for result in response.results:
56+
print('Transcript: {}'.format(result.alternatives[0].transcript))
5857
# [END migration_sync_response]
5958
# [END def_transcribe_file]
6059

@@ -76,10 +75,9 @@ def transcribe_gcs(gcs_uri):
7675
# [END migration_audio_config_gcs]
7776

7877
response = client.recognize(config, audio)
79-
alternatives = response.results[0].alternatives
80-
81-
for alternative in alternatives:
82-
print('Transcript: {}'.format(alternative.transcript))
78+
# Print the first alternative of all the consecutive results.
79+
for result in response.results:
80+
print('Transcript: {}'.format(result.alternatives[0].transcript))
8381
# [END def_transcribe_gcs]
8482

8583

‎speech/cloud-client/transcribe_async.py

Copy file name to clipboardExpand all lines: speech/cloud-client/transcribe_async.py
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ def transcribe_file(speech_file):
4949
# [END migration_async_request]
5050

5151
print('Waiting for operation to complete...')
52-
result = operation.result(timeout=90)
52+
response = operation.result(timeout=90)
5353

54-
alternatives = result.results[0].alternatives
55-
for alternative in alternatives:
56-
print('Transcript: {}'.format(alternative.transcript))
57-
print('Confidence: {}'.format(alternative.confidence))
54+
# Print the first alternative of all the consecutive results.
55+
for result in response.results:
56+
print('Transcript: {}'.format(result.alternatives[0].transcript))
57+
print('Confidence: {}'.format(result.alternatives[0].confidence))
5858
# [END migration_async_response]
5959
# [END def_transcribe_file]
6060

@@ -76,12 +76,12 @@ def transcribe_gcs(gcs_uri):
7676
operation = client.long_running_recognize(config, audio)
7777

7878
print('Waiting for operation to complete...')
79-
result = operation.result(timeout=90)
79+
response = operation.result(timeout=90)
8080

81-
alternatives = result.results[0].alternatives
82-
for alternative in alternatives:
83-
print('Transcript: {}'.format(alternative.transcript))
84-
print('Confidence: {}'.format(alternative.confidence))
81+
# Print the first alternative of all the consecutive results.
82+
for result in response.results:
83+
print('Transcript: {}'.format(result.alternatives[0].transcript))
84+
print('Confidence: {}'.format(result.alternatives[0].confidence))
8585
# [END def_transcribe_gcs]
8686

8787

‎speech/cloud-client/transcribe_streaming_mic.py

Copy file name to clipboardExpand all lines: speech/cloud-client/transcribe_streaming_mic.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ def listen_print_loop(responses):
129129
if not response.results:
130130
continue
131131

132-
# There could be multiple results in each response.
132+
# The `results` list is consecutive. For streaming, we only care about
133+
# the first result being considered, since once it's `is_final`, it
134+
# moves on to considering the next utterance.
133135
result = response.results[0]
134136
if not result.alternatives:
135137
continue

‎speech/cloud-client/transcribe_word_time_offsets.py

Copy file name to clipboardExpand all lines: speech/cloud-client/transcribe_word_time_offsets.py
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ def transcribe_file_with_word_time_offsets(speech_file):
4646

4747
response = client.recognize(config, audio)
4848

49-
alternatives = response.results[0].alternatives
50-
51-
for alternative in alternatives:
49+
for result in response.results:
50+
alternative = result.alternatives[0]
5251
print('Transcript: {}'.format(alternative.transcript))
5352

5453
for word_info in alternative.words:
@@ -82,8 +81,8 @@ def transcribe_gcs_with_word_time_offsets(gcs_uri):
8281
print('Waiting for operation to complete...')
8382
result = operation.result(timeout=90)
8483

85-
alternatives = result.results[0].alternatives
86-
for alternative in alternatives:
84+
for result in result.results:
85+
alternative = result.alternatives[0]
8786
print('Transcript: {}'.format(alternative.transcript))
8887
print('Confidence: {}'.format(alternative.confidence))
8988

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.