Skip to content

Commit da3d0c9

Browse files
committed
Feedback updates.
1 parent c65ea41 commit da3d0c9

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

system_tests/run_system_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
import logging_
2424
import monitoring
2525
import pubsub
26-
import storage
2726
import speech
27+
import storage
2828
import system_test_utils
2929
import translate
3030

3131

3232
TEST_MODULES = {
3333
'datastore': datastore,
34-
'storage': storage,
3534
'speech': speech,
35+
'storage': storage,
3636
'pubsub': pubsub,
3737
'bigquery': bigquery,
3838
'bigtable': bigtable,

system_tests/speech.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,45 @@
1717

1818
class TestSpeechClient(unittest.TestCase):
1919

20-
def test_sync_recognize_local_file(self):
21-
import io
20+
def _make_sync_request(self, content=None, source_uri=None,
21+
max_alternatives=None):
22+
from google.cloud.speech.encoding import Encoding
2223
from google.cloud import speech
24+
2325
client = speech.Client()
26+
sample = client.sample(content=content,
27+
source_uri=source_uri,
28+
encoding=Encoding.LINEAR16,
29+
sample_rate=16000)
30+
result = client.sync_recognize(sample,
31+
language_code='en-US',
32+
max_alternatives=max_alternatives,
33+
profanity_filter=True,
34+
speech_context=['Google',
35+
'cloud'])
36+
return result
37+
38+
def test_sync_recognize_local_file(self):
2439
file_name = 'system_tests/data/hello.wav'
2540

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,
41+
with open(file_name, 'rb') as file_obj:
42+
result = self._make_sync_request(content=file_obj.read(),
43+
max_alternatives=2)
44+
45+
self.assertEqual(result[0]['transcript'],
3646
'hello thank you for using Google Cloud platform')
37-
self.assertEqual(len(res), 2)
47+
self.assertGreater(result[0]['confidence'], .90)
48+
self.assertEqual(result[1]['transcript'],
49+
'thank you for using Google Cloud platform')
50+
self.assertEqual(len(result), 2)
3851

3952
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'
53+
import os
4354

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,
55+
source_uri = os.getenv('SPEECH_GCS_URI')
56+
result = self._make_sync_request(source_uri=source_uri,
57+
max_alternatives=1)
58+
self.assertEqual(result[0]['transcript'],
5359
'hello thank you for using Google Cloud platform')
54-
self.assertEqual(len(res), 1)
60+
self.assertGreater(result[0]['confidence'], .90)
61+
self.assertEqual(len(result), 1)

0 commit comments

Comments
 (0)