Skip to content

Commit

Permalink
Add test for speech sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerjou Cheng committed Mar 25, 2016
1 parent 4831117 commit d01c6ad
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions speech/api/speechrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import argparse
import base64
import json
import os

from googleapiclient import discovery

Expand All @@ -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]


Expand Down Expand Up @@ -67,7 +69,7 @@ def main(speech_file):
'sampleRate': 16000
},
'audioRequest': {
'content': speech_content
'content': speech_content.decode('UTF-8')
}
})
# [END construct_request]
Expand Down
23 changes: 23 additions & 0 deletions speech/api/speechrest_test.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d01c6ad

Please sign in to comment.