From e3fcefdffce813b78378e8aa5b2097944bd5d0b2 Mon Sep 17 00:00:00 2001 From: Jerjou Date: Tue, 26 Jul 2016 12:56:58 -0700 Subject: [PATCH] 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 --- appengine/standard/memcache/guestbook/main.py | 2 +- speech/api/speech_async_grpc.py | 10 ++++++++-- speech/api/speech_async_rest.py | 8 ++++++-- speech/api/speech_grpc.py | 10 ++++++++-- speech/api/speech_rest.py | 8 ++++++-- speech/api/speech_streaming.py | 12 ++++++++++-- vision/api/face_detection/faces.py | 4 ++-- vision/api/face_detection/faces_test.py | 2 +- 8 files changed, 42 insertions(+), 14 deletions(-) diff --git a/appengine/standard/memcache/guestbook/main.py b/appengine/standard/memcache/guestbook/main.py index fbe850e49257..d0ff0439e9ca 100644 --- a/appengine/standard/memcache/guestbook/main.py +++ b/appengine/standard/memcache/guestbook/main.py @@ -20,8 +20,8 @@ # [START all] -import cgi import cStringIO +import cgi import logging import urllib diff --git a/speech/api/speech_async_grpc.py b/speech/api/speech_async_grpc.py index 3186d9f30603..dfe35660d624 100644 --- a/speech/api/speech_async_grpc.py +++ b/speech/api/speech_async_grpc.py @@ -59,8 +59,14 @@ 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 + # See + # https://g.co/cloud/speech/docs/best-practices#language_support + # for a list of supported languages. + language_code='en-US', # a BCP-47 language tag ), audio=cloud_speech_pb2.RecognitionAudio( uri=input_uri, diff --git a/speech/api/speech_async_rest.py b/speech/api/speech_async_rest.py index a06102e69033..a1511c823657 100644 --- a/speech/api/speech_async_rest.py +++ b/speech/api/speech_async_rest.py @@ -57,8 +57,12 @@ 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 + # See https://goo.gl/DPeVFW for a list of supported languages. + 'languageCode': 'en-US', # a BCP-47 language tag }, 'audio': { 'content': speech_content.decode('UTF-8') diff --git a/speech/api/speech_grpc.py b/speech/api/speech_grpc.py index 8aa0aeb72c0f..b519e29e8f6f 100644 --- a/speech/api/speech_grpc.py +++ b/speech/api/speech_grpc.py @@ -56,8 +56,14 @@ 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 + # See + # https://g.co/cloud/speech/docs/best-practices#language_support + # for a list of supported languages. + language_code='en-US', # a BCP-47 language tag ), audio=cloud_speech.RecognitionAudio( uri=input_uri, diff --git a/speech/api/speech_rest.py b/speech/api/speech_rest.py index e6f83fb4a6e4..6f5c80d8a6db 100644 --- a/speech/api/speech_rest.py +++ b/speech/api/speech_rest.py @@ -60,8 +60,12 @@ 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 + # See https://goo.gl/DPeVFW for a list of supported languages. + 'languageCode': 'en-US', # a BCP-47 language tag }, 'audio': { 'content': speech_content.decode('UTF-8') diff --git a/speech/api/speech_streaming.py b/speech/api/speech_streaming.py index 560b072990fa..d4bd86685af8 100644 --- a/speech/api/speech_streaming.py +++ b/speech/api/speech_streaming.py @@ -83,13 +83,21 @@ 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 + # See + # https://g.co/cloud/speech/docs/best-practices#language_support + # for a list of supported languages. + 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 diff --git a/vision/api/face_detection/faces.py b/vision/api/face_detection/faces.py index d45c2a27b016..dab28645dd28 100755 --- a/vision/api/face_detection/faces.py +++ b/vision/api/face_detection/faces.py @@ -19,10 +19,10 @@ import argparse import base64 -from googleapiclient import discovery -from oauth2client.client import GoogleCredentials from PIL import Image from PIL import ImageDraw +from googleapiclient import discovery +from oauth2client.client import GoogleCredentials # [START get_vision_service] diff --git a/vision/api/face_detection/faces_test.py b/vision/api/face_detection/faces_test.py index 43a0075856d9..4d846b79e66d 100644 --- a/vision/api/face_detection/faces_test.py +++ b/vision/api/face_detection/faces_test.py @@ -13,8 +13,8 @@ import os -from faces import main from PIL import Image +from faces import main def test_main(resource, tmpdir):