From 7bac0575dec60a0a1c08c6b5944c2fe0d76103fe Mon Sep 17 00:00:00 2001 From: Jerjou Cheng Date: Fri, 22 Jul 2016 15:21:15 -0700 Subject: [PATCH 1/2] Add comments for config options. Some folks were tripping up on this. --- 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 ++++++++++-- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/speech/api/speech_async_grpc.py b/speech/api/speech_async_grpc.py index 3186d9f3060..dfe35660d62 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 a06102e6903..a1511c82365 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 8aa0aeb72c0..b519e29e8f6 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 e6f83fb4a6e..6f5c80d8a6d 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 560b072990f..d4bd86685af 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 From b0095829d67e2dc93d50c1652d7e84ebd8317319 Mon Sep 17 00:00:00 2001 From: Jerjou Cheng Date: Tue, 26 Jul 2016 12:42:48 -0700 Subject: [PATCH 2/2] Fix lint for new flake8-import-order --- appengine/standard/memcache/guestbook/main.py | 2 +- vision/api/face_detection/faces.py | 4 ++-- vision/api/face_detection/faces_test.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/appengine/standard/memcache/guestbook/main.py b/appengine/standard/memcache/guestbook/main.py index fbe850e4925..d0ff0439e9c 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/vision/api/face_detection/faces.py b/vision/api/face_detection/faces.py index d45c2a27b01..dab28645dd2 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 43a0075856d..4d846b79e66 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):