Skip to content

Commit

Permalink
Add comments for config options.
Browse files Browse the repository at this point in the history
Some folks were tripping up on this.
  • Loading branch information
Jerjou Cheng committed Jul 25, 2016
1 parent 439ca4c commit c1b191a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
7 changes: 5 additions & 2 deletions speech/api/speech_async_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ def main(input_uri, encoding, sample_rate):
# https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1beta1/cloud_speech.proto
response = service.AsyncRecognize(cloud_speech_pb2.AsyncRecognizeRequest(
config=cloud_speech_pb2.RecognitionConfig(
encoding=encoding,
sample_rate=sample_rate,
# There are a bunch of config options you can specify. See
# https://goo.gl/A6xv5G for the full list.
encoding=encoding, # one of LINEAR16, FLAC, MULAW, AMR, AMR_WB
sample_rate=sample_rate, # the rate in hertz
language_code='en-US', # a BCP-47 language tag
),
audio=cloud_speech_pb2.RecognitionAudio(
uri=input_uri,
Expand Down
7 changes: 5 additions & 2 deletions speech/api/speech_async_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ def main(speech_file):
service_request = service.speech().asyncrecognize(
body={
'config': {
'encoding': 'LINEAR16',
'sampleRate': 16000
# There are a bunch of config options you can specify. See
# https://goo.gl/EPjAup for the full list.
'encoding': 'LINEAR16', # raw 16-bit signed LE samples
'sampleRate': 16000, # 16 khz
'languageCode': 'en-US', # a BCP-47 language tag
},
'audio': {
'content': speech_content.decode('UTF-8')
Expand Down
7 changes: 5 additions & 2 deletions speech/api/speech_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ def main(input_uri, encoding, sample_rate):
# https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1beta1/cloud_speech.proto
response = service.SyncRecognize(cloud_speech.SyncRecognizeRequest(
config=cloud_speech.RecognitionConfig(
encoding=encoding,
sample_rate=sample_rate,
# There are a bunch of config options you can specify. See
# https://goo.gl/A6xv5G for the full list.
encoding=encoding, # one of LINEAR16, FLAC, MULAW, AMR, AMR_WB
sample_rate=sample_rate, # the rate in hertz
language_code='en-US', # a BCP-47 language tag
),
audio=cloud_speech.RecognitionAudio(
uri=input_uri,
Expand Down
7 changes: 5 additions & 2 deletions speech/api/speech_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ def main(speech_file):
service_request = service.speech().syncrecognize(
body={
'config': {
'encoding': 'LINEAR16',
'sampleRate': 16000
# There are a bunch of config options you can specify. See
# https://goo.gl/EPjAup for the full list.
'encoding': 'LINEAR16', # raw 16-bit signed LE samples
'sampleRate': 16000, # 16 khz
'languageCode': 'en-US', # a BCP-47 language tag
},
'audio': {
'content': speech_content.decode('UTF-8')
Expand Down
9 changes: 7 additions & 2 deletions speech/api/speech_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,18 @@ def request_stream(stop_audio, channels=CHANNELS, rate=RATE, chunk=CHUNK):
Args:
stop_audio: A threading.Event object stops the recording when set.
channels: How many audio channels to record.
rate: The sampling rate.
rate: The sampling rate in hertz.
chunk: Buffer audio into chunks of this size before sending to the api.
"""
# The initial request must contain metadata about the stream, so the
# server knows how to interpret it.
recognition_config = cloud_speech.RecognitionConfig(
encoding='LINEAR16', sample_rate=rate)
# There are a bunch of config options you can specify. See
# https://goo.gl/A6xv5G for the full list.
encoding='LINEAR16', # raw 16-bit signed LE samples
sample_rate=rate, # the rate in hertz
language_code='en-US', # a BCP-47 language tag
)
streaming_config = cloud_speech.StreamingRecognitionConfig(
config=recognition_config,
# Note that setting interim_results to True means that you'll likely
Expand Down

0 comments on commit c1b191a

Please sign in to comment.