Skip to content

Commit 0b67963

Browse files
author
Jerjou Cheng
committed
Add comments for config options.
Some folks were tripping up on this.
1 parent 439ca4c commit 0b67963

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

speech/api/speech_async_grpc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ def main(input_uri, encoding, sample_rate):
5959
# https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1beta1/cloud_speech.proto
6060
response = service.AsyncRecognize(cloud_speech_pb2.AsyncRecognizeRequest(
6161
config=cloud_speech_pb2.RecognitionConfig(
62-
encoding=encoding,
63-
sample_rate=sample_rate,
62+
# There are a bunch of config options you can specify. See
63+
# https://g.co/cloud/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1beta1.RecognitionConfig # noqa
64+
# for the full list.
65+
encoding=encoding, # one of LINEAR16, FLAC, MULAW, AMR, AMR_WB
66+
sample_rate=sample_rate, # the rate in hertz
67+
language_code='en-US', # a BCP-47 language tag
6468
),
6569
audio=cloud_speech_pb2.RecognitionAudio(
6670
uri=input_uri,

speech/api/speech_async_rest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ def main(speech_file):
5757
service_request = service.speech().asyncrecognize(
5858
body={
5959
'config': {
60-
'encoding': 'LINEAR16',
61-
'sampleRate': 16000
60+
# There are a bunch of config options you can specify. See
61+
# https://cloud.google.com/speech/reference/rest/Shared.Types/RecognitionConfig # noqa
62+
# for the full list.
63+
'encoding': 'LINEAR16', # raw 16-bit signed LE samples
64+
'sampleRate': 16000, # 16 khz
65+
'languageCode': 'en-US', # a BCP-47 language tag
6266
},
6367
'audio': {
6468
'content': speech_content.decode('UTF-8')

speech/api/speech_grpc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ def main(input_uri, encoding, sample_rate):
5656
# https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1beta1/cloud_speech.proto
5757
response = service.SyncRecognize(cloud_speech.SyncRecognizeRequest(
5858
config=cloud_speech.RecognitionConfig(
59-
encoding=encoding,
60-
sample_rate=sample_rate,
59+
# There are a bunch of config options you can specify. See
60+
# https://g.co/cloud/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1beta1.RecognitionConfig # noqa
61+
# for the full list.
62+
encoding=encoding, # one of LINEAR16, FLAC, MULAW, AMR, AMR_WB
63+
sample_rate=sample_rate, # the rate in hertz
64+
language_code='en-US', # a BCP-47 language tag
6165
),
6266
audio=cloud_speech.RecognitionAudio(
6367
uri=input_uri,

speech/api/speech_rest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ def main(speech_file):
6060
service_request = service.speech().syncrecognize(
6161
body={
6262
'config': {
63-
'encoding': 'LINEAR16',
64-
'sampleRate': 16000
63+
# There are a bunch of config options you can specify. See
64+
# https://cloud.google.com/speech/reference/rest/Shared.Types/RecognitionConfig # noqa
65+
# for the full list.
66+
'encoding': 'LINEAR16', # raw 16-bit signed LE samples
67+
'sampleRate': 16000, # 16 khz
68+
'languageCode': 'en-US', # a BCP-47 language tag
6569
},
6670
'audio': {
6771
'content': speech_content.decode('UTF-8')

speech/api/speech_streaming.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,19 @@ def request_stream(stop_audio, channels=CHANNELS, rate=RATE, chunk=CHUNK):
8383
Args:
8484
stop_audio: A threading.Event object stops the recording when set.
8585
channels: How many audio channels to record.
86-
rate: The sampling rate.
86+
rate: The sampling rate in hertz.
8787
chunk: Buffer audio into chunks of this size before sending to the api.
8888
"""
8989
# The initial request must contain metadata about the stream, so the
9090
# server knows how to interpret it.
9191
recognition_config = cloud_speech.RecognitionConfig(
92-
encoding='LINEAR16', sample_rate=rate)
92+
# There are a bunch of config options you can specify. See
93+
# https://g.co/cloud/speech/reference/rpc/google.cloud.speech.v1beta1#google.cloud.speech.v1beta1.RecognitionConfig # noqa
94+
# for the full list.
95+
encoding='LINEAR16', # raw 16-bit signed LE samples
96+
sample_rate=rate, # the rate in hertz
97+
language_code='en-US', # a BCP-47 language tag
98+
)
9399
streaming_config = cloud_speech.StreamingRecognitionConfig(
94100
config=recognition_config,
95101
# Note that setting interim_results to True means that you'll likely

0 commit comments

Comments
 (0)