-
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 async JSON/REST system tests. #2648
Add speech async JSON/REST system tests. #2648
Conversation
@@ -79,6 +79,21 @@ def _make_sync_request(self, content=None, source_uri=None, | |||
speech_context=['Google', 'cloud']) | |||
return result | |||
|
|||
def _make_async_request(self, content=None, source_uri=None, | |||
max_alternatives=None): | |||
client = speech.Client(use_gax=False) |
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.
profanity_filter=True, | ||
speech_context=['Google', 'cloud']) | ||
|
||
return result |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
import time | ||
with open(AUDIO_FILE, 'rb') as file_obj: | ||
operation = self._make_async_request(content=file_obj.read(), | ||
max_alternatives=2) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -109,3 +124,54 @@ def test_sync_recognize_gcs_file(self): | |||
result = self._make_sync_request(source_uri=source_uri, | |||
max_alternatives=1) | |||
self._check_best_results(result) | |||
|
|||
def test_async_recognize_local_file(self): | |||
import time |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
while retry_count > 0 and not operation.complete: | ||
retry_count -= 1 | ||
time.sleep(10) | ||
operation.poll() |
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.
source_uri = 'gs://%s/%s' % (bucket_name, blob_name) | ||
operation = self._make_async_request(source_uri=source_uri, | ||
max_alternatives=2) | ||
retry_count = 100 |
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.
retry_count = 100 | ||
while retry_count > 0 and not operation.complete: | ||
retry_count -= 1 | ||
time.sleep(10) |
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.
results = operation.results | ||
self.assertIsInstance(results[0], Transcript) | ||
self.assertEqual(results[0].transcript, 'hello ' + self.ASSERT_TEXT) | ||
self.assertGreater(results[0].confidence, 0.90) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
""" | ||
|
||
def _operation_complete(result): | ||
return result |
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.
@@ -126,29 +147,27 @@ def test_sync_recognize_gcs_file(self): | |||
self._check_best_results(result) | |||
|
|||
def test_async_recognize_local_file(self): | |||
import time | |||
if Config.USE_GAX: | |||
self.skipTest('async_recognize gRPC not yet implemented.') |
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.
LGTM (assuming you are tracking those |
:rtype: bool | ||
:returns: Boolean indicating if the operation is complete. | ||
""" | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM provided you are tracking skipTest
Ok I'm squashing now. Thanks! |
b79b1ee
to
80e4143
Compare
…est-system-tests Add speech async JSON/REST system tests.
This adds JSON/REST system tests for speech's
async_recognize()
method.