Skip to content

Commit

Permalink
Feedback updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
daspecster committed Oct 18, 2016
1 parent c65ea41 commit da3d0c9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
4 changes: 2 additions & 2 deletions system_tests/run_system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
import logging_
import monitoring
import pubsub
import storage
import speech
import storage
import system_test_utils
import translate


TEST_MODULES = {
'datastore': datastore,
'storage': storage,
'speech': speech,
'storage': storage,
'pubsub': pubsub,
'bigquery': bigquery,
'bigtable': bigtable,
Expand Down
59 changes: 33 additions & 26 deletions system_tests/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,45 @@

class TestSpeechClient(unittest.TestCase):

def test_sync_recognize_local_file(self):
import io
def _make_sync_request(self, content=None, source_uri=None,
max_alternatives=None):
from google.cloud.speech.encoding import Encoding
from google.cloud import speech

client = speech.Client()
sample = client.sample(content=content,
source_uri=source_uri,
encoding=Encoding.LINEAR16,
sample_rate=16000)
result = client.sync_recognize(sample,
language_code='en-US',
max_alternatives=max_alternatives,
profanity_filter=True,
speech_context=['Google',
'cloud'])
return result

def test_sync_recognize_local_file(self):
file_name = 'system_tests/data/hello.wav'

with io.open(file_name, 'rb') as file_obj:
sample = client.sample(content=file_obj.read(),
encoding=speech.Encoding.LINEAR16,
sample_rate=16000)
res = client.sync_recognize(sample,
language_code='en-US',
max_alternatives=2,
profanity_filter=True,
speech_context=['Google', 'cloud'])
self.assertEqual(res[0].transcript,
with open(file_name, 'rb') as file_obj:
result = self._make_sync_request(content=file_obj.read(),
max_alternatives=2)

self.assertEqual(result[0]['transcript'],
'hello thank you for using Google Cloud platform')
self.assertEqual(len(res), 2)
self.assertGreater(result[0]['confidence'], .90)
self.assertEqual(result[1]['transcript'],
'thank you for using Google Cloud platform')
self.assertEqual(len(result), 2)

def test_sync_recognize_gcs_file(self):
from google.cloud import speech
client = speech.Client()
source_uri = 'gs://ferrous-arena-my-test-bucket/hello.wav'
import os

sample = client.sample(source_uri=source_uri,
encoding=speech.Encoding.LINEAR16,
sample_rate=16000)
res = client.sync_recognize(sample,
language_code='en-US',
max_alternatives=1,
profanity_filter=True,
speech_context=['Google', 'cloud'])
self.assertEqual(res[0].transcript,
source_uri = os.getenv('SPEECH_GCS_URI')
result = self._make_sync_request(source_uri=source_uri,
max_alternatives=1)
self.assertEqual(result[0]['transcript'],
'hello thank you for using Google Cloud platform')
self.assertEqual(len(res), 1)
self.assertGreater(result[0]['confidence'], .90)
self.assertEqual(len(result), 1)

0 comments on commit da3d0c9

Please sign in to comment.