Skip to content

Commit d01c6ad

Browse files
author
Jerjou Cheng
committed
Add test for speech sample.
1 parent 4831117 commit d01c6ad

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

speech/api/speechrest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import argparse
2020
import base64
2121
import json
22+
import os
2223

2324
from googleapiclient import discovery
2425

@@ -29,7 +30,8 @@
2930

3031
# Path to local discovery file
3132
# [START discovery_doc]
32-
API_DISCOVERY_FILE = 'speech-discovery_google_rest_v1.json'
33+
API_DISCOVERY_FILE = os.path.join(
34+
os.path.dirname(__file__), 'speech-discovery_google_rest_v1.json')
3335
# [END discovery_doc]
3436

3537

@@ -67,7 +69,7 @@ def main(speech_file):
6769
'sampleRate': 16000
6870
},
6971
'audioRequest': {
70-
'content': speech_content
72+
'content': speech_content.decode('UTF-8')
7173
}
7274
})
7375
# [END construct_request]

speech/api/speechrest_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2016, Google, Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
import re
15+
16+
from speechrest import main
17+
18+
19+
def test_main(resource, capsys):
20+
main(resource('audio.raw'))
21+
out, err = capsys.readouterr()
22+
23+
assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I)

0 commit comments

Comments
 (0)