Skip to content

Commit e3fcefd

Browse files
authored
Add comments for speech config options, + fix lint errors for new flake8-import-order. (#429)
* Add comments for config options. Some folks were tripping up on this. * Fix lint for new flake8-import-order
1 parent 439ca4c commit e3fcefd

File tree

8 files changed

+42
-14
lines changed

8 files changed

+42
-14
lines changed

appengine/standard/memcache/guestbook/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
# [START all]
2222

23-
import cgi
2423
import cStringIO
24+
import cgi
2525
import logging
2626
import urllib
2727

speech/api/speech_async_grpc.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ 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://goo.gl/A6xv5G for the full list.
64+
encoding=encoding, # one of LINEAR16, FLAC, MULAW, AMR, AMR_WB
65+
sample_rate=sample_rate, # the rate in hertz
66+
# See
67+
# https://g.co/cloud/speech/docs/best-practices#language_support
68+
# for a list of supported languages.
69+
language_code='en-US', # a BCP-47 language tag
6470
),
6571
audio=cloud_speech_pb2.RecognitionAudio(
6672
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://goo.gl/EPjAup for the full list.
62+
'encoding': 'LINEAR16', # raw 16-bit signed LE samples
63+
'sampleRate': 16000, # 16 khz
64+
# See https://goo.gl/DPeVFW for a list of supported languages.
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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ 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://goo.gl/A6xv5G for the full list.
61+
encoding=encoding, # one of LINEAR16, FLAC, MULAW, AMR, AMR_WB
62+
sample_rate=sample_rate, # the rate in hertz
63+
# See
64+
# https://g.co/cloud/speech/docs/best-practices#language_support
65+
# for a list of supported languages.
66+
language_code='en-US', # a BCP-47 language tag
6167
),
6268
audio=cloud_speech.RecognitionAudio(
6369
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://goo.gl/EPjAup for the full list.
65+
'encoding': 'LINEAR16', # raw 16-bit signed LE samples
66+
'sampleRate': 16000, # 16 khz
67+
# See https://goo.gl/DPeVFW for a list of supported languages.
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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,21 @@ 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://goo.gl/A6xv5G for the full list.
94+
encoding='LINEAR16', # raw 16-bit signed LE samples
95+
sample_rate=rate, # the rate in hertz
96+
# See
97+
# https://g.co/cloud/speech/docs/best-practices#language_support
98+
# for a list of supported languages.
99+
language_code='en-US', # a BCP-47 language tag
100+
)
93101
streaming_config = cloud_speech.StreamingRecognitionConfig(
94102
config=recognition_config,
95103
# Note that setting interim_results to True means that you'll likely

vision/api/face_detection/faces.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import argparse
2020
import base64
2121

22-
from googleapiclient import discovery
23-
from oauth2client.client import GoogleCredentials
2422
from PIL import Image
2523
from PIL import ImageDraw
24+
from googleapiclient import discovery
25+
from oauth2client.client import GoogleCredentials
2626

2727

2828
# [START get_vision_service]

vision/api/face_detection/faces_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
import os
1515

16-
from faces import main
1716
from PIL import Image
17+
from faces import main
1818

1919

2020
def test_main(resource, tmpdir):

0 commit comments

Comments
 (0)