Skip to content

Commit aa3b0f5

Browse files
committed
Add Speech sync recognize system test.
1 parent 4becc0c commit aa3b0f5

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

system_tests/attempt_system_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
MODULES = ( # ordered from most to least stable
6060
'datastore',
6161
'storage',
62+
'speech',
6263
'bigquery',
6364
'pubsub',
6465
'language',

system_tests/data/hello.wav

119 KB
Binary file not shown.

system_tests/run_system_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
import monitoring
2525
import pubsub
2626
import storage
27+
import speech
2728
import system_test_utils
2829
import translate
2930

3031

3132
TEST_MODULES = {
3233
'datastore': datastore,
3334
'storage': storage,
35+
'speech': speech,
3436
'pubsub': pubsub,
3537
'bigquery': bigquery,
3638
'bigtable': bigtable,

system_tests/speech.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
17+
18+
class TestSpeechClient(unittest.TestCase):
19+
20+
def test_sync_recognize_local_file(self):
21+
import io
22+
from google.cloud import speech
23+
client = speech.Client()
24+
file_name = 'system_tests/data/hello.wav'
25+
26+
with io.open(file_name, 'rb') as file_obj:
27+
sample = client.sample(content=file_obj.read(),
28+
encoding=speech.Encoding.LINEAR16,
29+
sample_rate=16000)
30+
res = client.sync_recognize(sample,
31+
language_code='en-US',
32+
max_alternatives=2,
33+
profanity_filter=True,
34+
speech_context=['Google', 'cloud'])
35+
self.assertEqual(res[0].transcript,
36+
'hello thank you for using Google Cloud platform')
37+
self.assertEqual(len(res), 2)
38+
39+
def test_sync_recognize_gcs_file(self):
40+
from google.cloud import speech
41+
client = speech.Client()
42+
source_uri = 'gs://ferrous-arena-my-test-bucket/hello.wav'
43+
44+
sample = client.sample(source_uri=source_uri,
45+
encoding=speech.Encoding.LINEAR16,
46+
sample_rate=16000)
47+
res = client.sync_recognize(sample,
48+
language_code='en-US',
49+
max_alternatives=1,
50+
profanity_filter=True,
51+
speech_context=['Google', 'cloud'])
52+
self.assertEqual(res[0].transcript,
53+
'hello thank you for using Google Cloud platform')
54+
self.assertEqual(len(res), 1)

0 commit comments

Comments
 (0)