-
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 gapic #2663
Add speech async gapic #2663
Conversation
0e14c9d
to
5078aa4
Compare
54b981b
to
eb08066
Compare
eb08066
to
46cd146
Compare
@@ -51,6 +51,8 @@ | |||
|
|||
REQUIREMENTS = [ | |||
'google-cloud-core >= 0.20.0', | |||
'grpcio >= 1.0.0, < 2.0dev', | |||
'google-gax >= 0.14.1, < 0.15dev', |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
0ca8559
to
bf805e3
Compare
from google.cloud._helpers import make_secure_stub | ||
from google.cloud.connection import DEFAULT_USER_AGENT | ||
from google.cloud.speech.operation import Operation | ||
from google.cloud.operation import register_type |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
OPERATIONS_API_HOST = 'speech.googleapis.com' | ||
|
||
register_type(AsyncRecognizeMetadata) | ||
register_type(AsyncRecognizeResponse) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -72,9 +88,26 @@ def async_recognize(self, sample, language_code=None, | |||
and phrases. This can also be used to add new | |||
words to the vocabulary of the recognizer. | |||
|
|||
:raises NotImplementedError: Always. | |||
:rtype: :class:`~google.cloud.operation.Opeartion` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
api = self._gapic_api | ||
response = api.async_recognize(config=config, audio=audio) | ||
|
||
self._client._operations_stub = make_secure_stub( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -52,7 +52,6 @@ | |||
REQUIREMENTS = [ | |||
'google-cloud-core >= 0.20.0', | |||
'gapic-google-cloud-speech-v1beta1 >= 0.11.1, < 0.12.0', | |||
'grpc-google-cloud-speech-v1beta1 >= 0.11.1, < 0.12.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.
@@ -199,11 +199,10 @@ def test_sync_recognize_with_empty_results_gax(self): | |||
credentials = _Credentials() | |||
client = self._makeOne(credentials=credentials, use_gax=True) | |||
client.connection = _Connection() | |||
_MockGAPICSpeechAPI._results = [] |
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.
@@ -277,13 +274,16 @@ def test_async_recognize_with_gax(self): | |||
credentials = _Credentials() | |||
client = self._makeOne(credentials=credentials) | |||
client.connection = _Connection() | |||
client.connection.credentials = credentials |
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.
operation = client.async_recognize(sample) | ||
|
||
self.assertFalse(operation.complete) | ||
self.assertIsNone(operation.response) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -321,28 +321,40 @@ class _MockGAPICAlternative(object): | |||
confidence = 0.95234356 | |||
|
|||
|
|||
class _MockGAPICMetadata(object): | |||
type_url = None |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
375feeb
to
2e9f486
Compare
@dhermes I think there are just thow two open questions. Did you have anything else? |
@staticmethod | ||
def _make_result(transcript, confidence): | ||
from google.cloud.grpc.speech.v1beta1 import cloud_speech_pb2 | ||
return cloud_speech_pb2.SpeechRecognitionResult( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
alternatives=[ | ||
cloud_speech_pb2.SpeechRecognitionAlternative( | ||
transcript=transcript, | ||
confidence=confidence, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
def _make_sync_response(self, *results): | ||
from google.cloud.grpc.speech.v1beta1 import cloud_speech_pb2 | ||
response = cloud_speech_pb2.SyncRecognizeResponse( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
from google.cloud import speech | ||
from google.cloud.speech import _gax as MUT |
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.
from google.cloud.speech.sample import Sample | ||
|
||
credentials = _Credentials() | ||
client = self._makeOne(credentials=credentials, use_gax=True) | ||
client.connection = _Connection() | ||
client.connection.credentials = credentials | ||
|
||
_MockGAPICSpeechAPI._response = self._make_sync_response() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -277,13 +274,16 @@ def test_async_recognize_with_gax(self): | |||
credentials = _Credentials() | |||
client = self._makeOne(credentials=credentials) | |||
client.connection = _Connection() | |||
client.connection.credentials = credentials |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
mock_response = self._response | ||
mock_response.results = self._results | ||
return mock_response | ||
# self._response.results = self._results |
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 = None | ||
|
||
def async_recognize(self, config, audio): | ||
from google.longrunning.operations_pb2 import Operation |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
"confidence": 0.9224355 | ||
}, { | ||
"transcript": 'testing 4 5 6', | ||
"confidence": 0.0123456 |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
with self.assertRaises(ValueError): | ||
with _Monkey(MUT, SpeechApi=_MockGAPICSpeechAPI): | ||
with _Monkey(_gax, SpeechApi=speech_api): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self.assertEqual(results[1].transcript, | ||
alternatives[1]['transcript']) | ||
self.assertEqual(results[1].confidence, | ||
alternatives[1]['confidence']) |
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 clear up my most recent comments and resolve the setup.py
question for @jonparrott
77b6d16
to
5d4272f
Compare
Travis has gone on strike again... |
Finally travis ran this job. @dhermes, I'm merging(in 15minutes) since I got your suggestions in. |
Feel free to merge now |
…apic Add speech async gapic
This will need #2661 in order for travis-ci to pass since I don't needmetadata.py
andoperation.py
after @dhermes refactored the coreoperation.py
@ Thanks!@dhermes, I think we talked about this back and forth a little bit, but as you can see from the system tests, the surface is much different between
sync_recognize()
's results andasync_recognize()
's results.There will be some updates for the gRPC version of
sync_recognize()
that will follow this as well.