-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Speech sync recognize system test. #2547
Add Speech sync recognize system test. #2547
Conversation
@@ -24,13 +24,15 @@ | |||
import monitoring | |||
import pubsub | |||
import storage | |||
import speech |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
import io | ||
from google.cloud import speech | ||
client = speech.Client() | ||
file_name = 'system_tests/data/hello.wav' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
client = speech.Client() | ||
file_name = 'system_tests/data/hello.wav' | ||
|
||
with io.open(file_name, 'rb') as file_obj: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
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' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
def test_sync_recognize_gcs_file(self): | ||
from google.cloud import speech | ||
client = speech.Client() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
speech_context=['Google', 'cloud']) | ||
self.assertEqual(res[0].transcript, | ||
'hello thank you for using Google Cloud platform') | ||
self.assertEqual(len(res), 1) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
sample = client.sample(content=file_obj.read(), | ||
encoding=speech.Encoding.LINEAR16, | ||
sample_rate=16000) | ||
res = client.sync_recognize(sample, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
max_alternatives=2, | ||
profanity_filter=True, | ||
speech_context=['Google', 'cloud']) | ||
self.assertEqual(res[0].transcript, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
speech_context=['Google', 'cloud']) | ||
self.assertEqual(res[0].transcript, | ||
'hello thank you for using Google Cloud platform') | ||
self.assertEqual(len(res), 2) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@dhermes, I had to change how the transcript and confidence values are accessed. I think I was running this before with a different version installed so I had them as properties. The result for |
It's tough to review a moving target. Are the tested methods done and checked in? If yes, then why the out-of-sync issue? |
max_alternatives=1) | ||
self.assertEqual(result[0]['transcript'], | ||
'hello thank you for using Google Cloud platform') | ||
self.assertGreater(result[0]['confidence'], .90) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
result = self._make_sync_request(content=file_obj.read(), | ||
max_alternatives=2) | ||
|
||
self.assertEqual(result[0]['transcript'], |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
def test_sync_recognize_gcs_file(self): | ||
import os | ||
|
||
source_uri = os.getenv('SPEECH_GCS_URI') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return result | ||
|
||
def test_sync_recognize_local_file(self): | ||
file_name = 'system_tests/data/hello.wav' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
self.assertEqual(result[0]['transcript'], | ||
'hello thank you for using Google Cloud platform') | ||
self.assertGreater(result[0]['confidence'], .90) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
def _make_sync_request(self, content=None, source_uri=None, | ||
max_alternatives=None): | ||
from google.cloud.speech.encoding import Encoding |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
da3d0c9
to
c30ea2f
Compare
|
||
class Config(object): | ||
"""Run-time configuration to be modified at set-up. | ||
This is a mutable stand-in to allow test set-up to modify |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
max_alternatives=max_alternatives, | ||
profanity_filter=True, | ||
speech_context=['Google', | ||
'cloud']) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return result | ||
|
||
def _check_best_results(self, results): | ||
from google.cloud.speech.transcript import Transcript |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
def test_sync_recognize_local_file(self): | ||
import os | ||
from google.cloud.speech.transcript import Transcript |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
import os | ||
from google.cloud.speech.transcript import Transcript | ||
|
||
file_name = os.path.join('system_tests', 'data', 'hello.wav') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self.assertIsInstance(second_alternative, Transcript) | ||
self.assertEqual(second_alternative.transcript, | ||
'thank you for using Google Cloud platform') | ||
self.assertEqual(second_alternative.confidence, 0.0) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self._check_best_results(results) | ||
self.assertIsInstance(second_alternative, Transcript) | ||
self.assertEqual(second_alternative.transcript, | ||
'thank you for using Google Cloud platform') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
with open(file_name, 'rb') as file_obj: | ||
blob.upload_from_file(file_obj) | ||
|
||
# source_uri = os.getenv('SPEECH_GCS_URI') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
def test_sync_recognize_gcs_file(self): | ||
import os | ||
|
||
file_name = os.path.join('system_tests', 'data', 'hello.wav') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
file_name = os.path.join('system_tests', 'data', 'hello.wav') | ||
bucket_name = Config.TEST_BUCKET.name | ||
blob_name = 'document.txt' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This is a mutable stand-in to allow test set-up to modify | ||
global state. | ||
""" | ||
CLIENT = None | ||
TEST_BUCKET = None | ||
AUDIO_FILE = os.path.join(os.path.dirname(__file__), 'data', 'hello.wav') | ||
ASSERT_TEXT = 'thank you for using Google Cloud platform' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This is a mutable stand-in to allow test set-up to modify | ||
global state. | ||
""" | ||
CLIENT = None | ||
TEST_BUCKET = None | ||
AUDIO_FILE = os.path.join(os.path.dirname(__file__), 'data', 'hello.wav') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self._check_best_results(results) | ||
self.assertIsInstance(second_alternative, Transcript) | ||
self.assertEqual(second_alternative.transcript, Config.ASSERT_TEXT) | ||
self.assertEqual(second_alternative.confidence, 0.0) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
…stem-tests Add Speech sync recognize system test.
First swing at system tests for sync_recognize().
The GCS test is using a file(hello.wav) on my bucket so we'll probably want to upload that to the testing account.