Skip to content

Commit bcd4588

Browse files
alixhamidizcology
authored andcommitted
Speech region tag update [(#1644)](GoogleCloudPlatform/python-docs-samples#1644)
* update beta tags * updates tags for recognition-metadata page * update diarization tag to beta * update word level confidence tags to beta * updates region tags for async-recognize page * updates region tag for async-time-offsets * update region tags for sync transcribe * updates multichannel tags to beta * updates multilanguage tags to beta * update streaming region tags * updates async local tags and fixes beta tags * updates tags for migration guide * updates word time offsets region tag
1 parent 2273fd0 commit bcd4588

8 files changed

+52
-57
lines changed

samples/snippets/beta_snippets.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
def transcribe_file_with_enhanced_model():
3535
"""Transcribe the given audio file using an enhanced model."""
36-
# [START speech_transcribe_file_with_enhanced_model]
36+
# [START speech_transcribe_enhanced_model_beta]
3737
from google.cloud import speech_v1p1beta1 as speech
3838
client = speech.SpeechClient()
3939

@@ -60,12 +60,12 @@ def transcribe_file_with_enhanced_model():
6060
print('-' * 20)
6161
print('First alternative of result {}'.format(i))
6262
print('Transcript: {}'.format(alternative.transcript))
63-
# [END speech_transcribe_file_with_enhanced_model]
63+
# [END speech_transcribe_enhanced_model_beta]
6464

6565

6666
def transcribe_file_with_metadata():
6767
"""Send a request that includes recognition metadata."""
68-
# [START speech_transcribe_file_with_metadata]
68+
# [START speech_transcribe_recognition_metadata_beta]
6969
from google.cloud import speech_v1p1beta1 as speech
7070
client = speech.SpeechClient()
7171

@@ -105,12 +105,12 @@ def transcribe_file_with_metadata():
105105
print('-' * 20)
106106
print('First alternative of result {}'.format(i))
107107
print('Transcript: {}'.format(alternative.transcript))
108-
# [END speech_transcribe_file_with_metadata]
108+
# [END speech_transcribe_recognition_metadata_beta]
109109

110110

111111
def transcribe_file_with_auto_punctuation():
112112
"""Transcribe the given audio file with auto punctuation enabled."""
113-
# [START speech_transcribe_file_with_auto_punctuation]
113+
# [START speech_transcribe_auto_punctuation_beta]
114114
from google.cloud import speech_v1p1beta1 as speech
115115
client = speech.SpeechClient()
116116

@@ -134,12 +134,12 @@ def transcribe_file_with_auto_punctuation():
134134
print('-' * 20)
135135
print('First alternative of result {}'.format(i))
136136
print('Transcript: {}'.format(alternative.transcript))
137-
# [END speech_transcribe_file_with_auto_punctuation]
137+
# [END speech_transcribe_auto_punctuation_beta]
138138

139139

140140
def transcribe_file_with_diarization():
141141
"""Transcribe the given audio file synchronously with diarization."""
142-
# [START speech_transcribe_diarization]
142+
# [START speech_transcribe_diarization_beta]
143143
from google.cloud import speech_v1p1beta1 as speech
144144
client = speech.SpeechClient()
145145

@@ -172,13 +172,13 @@ def transcribe_file_with_diarization():
172172
for word_info in words_info:
173173
print("word: '{}', speaker_tag: {}".format(word_info.word,
174174
word_info.speaker_tag))
175-
# [END speech_transcribe_diarization]
175+
# [END speech_transcribe_diarization_beta]
176176

177177

178178
def transcribe_file_with_multichannel():
179179
"""Transcribe the given audio file synchronously with
180180
multi channel."""
181-
# [START speech_transcribe_multichannel]
181+
# [START speech_transcribe_multichannel_beta]
182182
from google.cloud import speech_v1p1beta1 as speech
183183
client = speech.SpeechClient()
184184

@@ -204,13 +204,13 @@ def transcribe_file_with_multichannel():
204204
print('First alternative of result {}'.format(i))
205205
print(u'Transcript: {}'.format(alternative.transcript))
206206
print(u'Channel Tag: {}'.format(result.channel_tag))
207-
# [END speech_transcribe_multichannel]
207+
# [END speech_transcribe_multichannel_beta]
208208

209209

210210
def transcribe_file_with_multilanguage():
211211
"""Transcribe the given audio file synchronously with
212212
multi language."""
213-
# [START speech_transcribe_multilanguage]
213+
# [START speech_transcribe_multilanguage_beta]
214214
from google.cloud import speech_v1p1beta1 as speech
215215
client = speech.SpeechClient()
216216

@@ -238,13 +238,13 @@ def transcribe_file_with_multilanguage():
238238
print('-' * 20)
239239
print('First alternative of result {}: {}'.format(i, alternative))
240240
print(u'Transcript: {}'.format(alternative.transcript))
241-
# [END speech_transcribe_multilanguage]
241+
# [END speech_transcribe_multilanguage_beta]
242242

243243

244244
def transcribe_file_with_word_level_confidence():
245245
"""Transcribe the given audio file synchronously with
246246
word level confidence."""
247-
# [START speech_transcribe_word_level_confidence]
247+
# [START speech_transcribe_word_level_confidence_beta]
248248
from google.cloud import speech_v1p1beta1 as speech
249249
client = speech.SpeechClient()
250250

@@ -270,7 +270,7 @@ def transcribe_file_with_word_level_confidence():
270270
print(u'Transcript: {}'.format(alternative.transcript))
271271
print(u'First Word and Confidence: ({}, {})'.format(
272272
alternative.words[0].word, alternative.words[0].confidence))
273-
# [END speech_transcribe_word_level_confidence]
273+
# [END speech_transcribe_word_level_confidence_beta]
274274

275275

276276
if __name__ == '__main__':

samples/snippets/quickstart.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ def run_quickstart():
2121
import os
2222

2323
# Imports the Google Cloud client library
24-
# [START migration_import]
24+
# [START speech_python_migration_imports]
2525
from google.cloud import speech
2626
from google.cloud.speech import enums
2727
from google.cloud.speech import types
28-
# [END migration_import]
28+
# [END speech_python_migration_imports]
2929

3030
# Instantiates a client
31-
# [START migration_client]
31+
# [START speech_python_migration_client]
3232
client = speech.SpeechClient()
33-
# [END migration_client]
33+
# [END speech_python_migration_client]
3434

3535
# The name of the audio file to transcribe
3636
file_name = os.path.join(

samples/snippets/transcribe.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,20 @@
2222
python transcribe.py gs://cloud-samples-tests/speech/brooklyn.flac
2323
"""
2424

25-
# [START import_libraries]
2625
import argparse
2726
import io
28-
# [END import_libraries]
2927

3028

31-
# [START def_transcribe_file]
29+
# [START speech_transcribe_sync]
3230
def transcribe_file(speech_file):
3331
"""Transcribe the given audio file."""
3432
from google.cloud import speech
3533
from google.cloud.speech import enums
3634
from google.cloud.speech import types
3735
client = speech.SpeechClient()
3836

39-
# [START migration_sync_request]
40-
# [START migration_audio_config_file]
37+
# [START speech_python_migration_sync_request]
38+
# [START speech_python_migration_config]
4139
with io.open(speech_file, 'rb') as audio_file:
4240
content = audio_file.read()
4341

@@ -46,43 +44,43 @@ def transcribe_file(speech_file):
4644
encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
4745
sample_rate_hertz=16000,
4846
language_code='en-US')
49-
# [END migration_audio_config_file]
47+
# [END speech_python_migration_config]
5048

51-
# [START migration_sync_response]
49+
# [START speech_python_migration_sync_response]
5250
response = client.recognize(config, audio)
53-
# [END migration_sync_request]
51+
# [END speech_python_migration_sync_request]
5452
# Each result is for a consecutive portion of the audio. Iterate through
5553
# them to get the transcripts for the entire audio file.
5654
for result in response.results:
5755
# The first alternative is the most likely one for this portion.
5856
print(u'Transcript: {}'.format(result.alternatives[0].transcript))
59-
# [END migration_sync_response]
60-
# [END def_transcribe_file]
57+
# [END speech_python_migration_sync_response]
58+
# [END speech_transcribe_sync]
6159

6260

63-
# [START def_transcribe_gcs]
61+
# [START speech_transcribe_sync_gcs]
6462
def transcribe_gcs(gcs_uri):
6563
"""Transcribes the audio file specified by the gcs_uri."""
6664
from google.cloud import speech
6765
from google.cloud.speech import enums
6866
from google.cloud.speech import types
6967
client = speech.SpeechClient()
7068

71-
# [START migration_audio_config_gcs]
69+
# [START speech_python_migration_config_gcs]
7270
audio = types.RecognitionAudio(uri=gcs_uri)
7371
config = types.RecognitionConfig(
7472
encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
7573
sample_rate_hertz=16000,
7674
language_code='en-US')
77-
# [END migration_audio_config_gcs]
75+
# [END speech_python_migration_config_gcs]
7876

7977
response = client.recognize(config, audio)
8078
# Each result is for a consecutive portion of the audio. Iterate through
8179
# them to get the transcripts for the entire audio file.
8280
for result in response.results:
8381
# The first alternative is the most likely one for this portion.
8482
print(u'Transcript: {}'.format(result.alternatives[0].transcript))
85-
# [END def_transcribe_gcs]
83+
# [END speech_transcribe_sync_gcs]
8684

8785

8886
if __name__ == '__main__':

samples/snippets/transcribe_async.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
import io
2727

2828

29-
# [START def_transcribe_file]
29+
# [START speech_transcribe_async]
3030
def transcribe_file(speech_file):
3131
"""Transcribe the given audio file asynchronously."""
3232
from google.cloud import speech
3333
from google.cloud.speech import enums
3434
from google.cloud.speech import types
3535
client = speech.SpeechClient()
3636

37-
# [START migration_async_request]
37+
# [START speech_python_migration_async_request]
3838
with io.open(speech_file, 'rb') as audio_file:
3939
content = audio_file.read()
4040

@@ -44,9 +44,9 @@ def transcribe_file(speech_file):
4444
sample_rate_hertz=16000,
4545
language_code='en-US')
4646

47-
# [START migration_async_response]
47+
# [START speech_python_migration_async_response]
4848
operation = client.long_running_recognize(config, audio)
49-
# [END migration_async_request]
49+
# [END speech_python_migration_async_request]
5050

5151
print('Waiting for operation to complete...')
5252
response = operation.result(timeout=90)
@@ -57,11 +57,11 @@ def transcribe_file(speech_file):
5757
# The first alternative is the most likely one for this portion.
5858
print(u'Transcript: {}'.format(result.alternatives[0].transcript))
5959
print('Confidence: {}'.format(result.alternatives[0].confidence))
60-
# [END migration_async_response]
61-
# [END def_transcribe_file]
60+
# [END speech_python_migration_async_response]
61+
# [END speech_transcribe_async]
6262

6363

64-
# [START def_transcribe_gcs]
64+
# [START speech_transcribe_async_gcs]
6565
def transcribe_gcs(gcs_uri):
6666
"""Asynchronously transcribes the audio file specified by the gcs_uri."""
6767
from google.cloud import speech
@@ -86,7 +86,7 @@ def transcribe_gcs(gcs_uri):
8686
# The first alternative is the most likely one for this portion.
8787
print(u'Transcript: {}'.format(result.alternatives[0].transcript))
8888
print('Confidence: {}'.format(result.alternatives[0].confidence))
89-
# [END def_transcribe_gcs]
89+
# [END speech_transcribe_async_gcs]
9090

9191

9292
if __name__ == '__main__':

samples/snippets/transcribe_model_selection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import argparse
2828

2929

30-
# [START speech_transcribe_model_selection]
30+
# [START speech_transcribe_model_selection_beta]
3131
def transcribe_model_selection(speech_file, model):
3232
"""Transcribe the given audio file synchronously with
3333
the selected model."""
@@ -52,10 +52,10 @@ def transcribe_model_selection(speech_file, model):
5252
print('-' * 20)
5353
print('First alternative of result {}'.format(i))
5454
print(u'Transcript: {}'.format(alternative.transcript))
55-
# [END speech_transcribe_model_selection]
55+
# [END speech_transcribe_model_selection_beta]
5656

5757

58-
# [START speech_transcribe_model_selection_gcs]
58+
# [START speech_transcribe_model_selection_gcs_beta]
5959
def transcribe_model_selection_gcs(gcs_uri, model):
6060
"""Transcribe the given audio file asynchronously with
6161
the selected model."""
@@ -80,7 +80,7 @@ def transcribe_model_selection_gcs(gcs_uri, model):
8080
print('-' * 20)
8181
print('First alternative of result {}'.format(i))
8282
print(u'Transcript: {}'.format(alternative.transcript))
83-
# [END speech_transcribe_model_selection_gcs]
83+
# [END speech_transcribe_model_selection_gcs_beta]
8484

8585

8686
if __name__ == '__main__':

samples/snippets/transcribe_streaming.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@
2020
python transcribe_streaming.py resources/audio.raw
2121
"""
2222

23-
# [START import_libraries]
2423
import argparse
2524
import io
26-
# [END import_libraries]
2725

2826

29-
# [START def_transcribe_streaming]
27+
# [START speech_transcribe_streaming]
3028
def transcribe_streaming(stream_file):
3129
"""Streams transcription of the given audio file."""
3230
from google.cloud import speech
3331
from google.cloud.speech import enums
3432
from google.cloud.speech import types
3533
client = speech.SpeechClient()
3634

37-
# [START migration_streaming_request]
35+
# [START speech_python_migration_streaming_request]
3836
with io.open(stream_file, 'rb') as audio_file:
3937
content = audio_file.read()
4038

@@ -50,9 +48,9 @@ def transcribe_streaming(stream_file):
5048
streaming_config = types.StreamingRecognitionConfig(config=config)
5149

5250
# streaming_recognize returns a generator.
53-
# [START migration_streaming_response]
51+
# [START speech_python_migration_streaming_response]
5452
responses = client.streaming_recognize(streaming_config, requests)
55-
# [END migration_streaming_request]
53+
# [END speech_python_migration_streaming_request]
5654

5755
for response in responses:
5856
# Once the transcription has settled, the first result will contain the
@@ -66,8 +64,8 @@ def transcribe_streaming(stream_file):
6664
for alternative in alternatives:
6765
print('Confidence: {}'.format(alternative.confidence))
6866
print(u'Transcript: {}'.format(alternative.transcript))
69-
# [END migration_streaming_response]
70-
# [END def_transcribe_streaming]
67+
# [END speech_python_migration_streaming_response]
68+
# [END speech_transcribe_streaming]
7169

7270

7371
if __name__ == '__main__':

samples/snippets/transcribe_streaming_mic.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
python transcribe_streaming_mic.py
2626
"""
2727

28-
# [START import_libraries]
28+
# [START speech_transcribe_streaming_mic]
2929
from __future__ import division
3030

3131
import re
@@ -36,7 +36,6 @@
3636
from google.cloud.speech import types
3737
import pyaudio
3838
from six.moves import queue
39-
# [END import_libraries]
4039

4140
# Audio recording parameters
4241
RATE = 16000
@@ -106,7 +105,6 @@ def generator(self):
106105
break
107106

108107
yield b''.join(data)
109-
# [END audio_stream]
110108

111109

112110
def listen_print_loop(responses):
@@ -191,3 +189,4 @@ def main():
191189

192190
if __name__ == '__main__':
193191
main()
192+
# [END speech_transcribe_streaming_mic]

samples/snippets/transcribe_word_time_offsets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def transcribe_file_with_word_time_offsets(speech_file):
6060
end_time.seconds + end_time.nanos * 1e-9))
6161

6262

63-
# [START def_transcribe_gcs]
63+
# [START speech_transcribe_async_word_time_offsets_gcs]
6464
def transcribe_gcs_with_word_time_offsets(gcs_uri):
6565
"""Transcribe the given audio file asynchronously and output the word time
6666
offsets."""
@@ -94,7 +94,7 @@ def transcribe_gcs_with_word_time_offsets(gcs_uri):
9494
word,
9595
start_time.seconds + start_time.nanos * 1e-9,
9696
end_time.seconds + end_time.nanos * 1e-9))
97-
# [END def_transcribe_gcs]
97+
# [END speech_transcribe_async_word_time_offsets_gcs]
9898

9999

100100
if __name__ == '__main__':

0 commit comments

Comments
 (0)