From d01c6ad11ec53849303d3d255cfe1840182a91b4 Mon Sep 17 00:00:00 2001 From: Jerjou Cheng Date: Fri, 25 Mar 2016 12:48:13 -0700 Subject: [PATCH] Add test for speech sample. --- speech/api/speechrest.py | 6 ++++-- speech/api/speechrest_test.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 speech/api/speechrest_test.py diff --git a/speech/api/speechrest.py b/speech/api/speechrest.py index 8e132b012d88..43a8e39f65c8 100644 --- a/speech/api/speechrest.py +++ b/speech/api/speechrest.py @@ -19,6 +19,7 @@ import argparse import base64 import json +import os from googleapiclient import discovery @@ -29,7 +30,8 @@ # Path to local discovery file # [START discovery_doc] -API_DISCOVERY_FILE = 'speech-discovery_google_rest_v1.json' +API_DISCOVERY_FILE = os.path.join( + os.path.dirname(__file__), 'speech-discovery_google_rest_v1.json') # [END discovery_doc] @@ -67,7 +69,7 @@ def main(speech_file): 'sampleRate': 16000 }, 'audioRequest': { - 'content': speech_content + 'content': speech_content.decode('UTF-8') } }) # [END construct_request] diff --git a/speech/api/speechrest_test.py b/speech/api/speechrest_test.py new file mode 100644 index 000000000000..8f1d2851bfa5 --- /dev/null +++ b/speech/api/speechrest_test.py @@ -0,0 +1,23 @@ +# Copyright 2016, Google, Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import re + +from speechrest import main + + +def test_main(resource, capsys): + main(resource('audio.raw')) + out, err = capsys.readouterr() + + assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I)