-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add Speech GAPIC for sync_recognize. #2615
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 GAPIC for sync_recognize. #2615
Conversation
dhermes
left a comment
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.
Some comments, as discussed in chat, the impl. should resemble the Pub/Sub and Logging implementations, i.e. separation of concerns by having HTTP-only and GAX-only API objects.
| return cls(transcript['transcript'], transcript['confidence']) | ||
|
|
||
| @classmethod | ||
| def from_pb(cls, transcript): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| def from_pb(cls, transcript): | ||
| """Factory: construct ``Transcript`` from protobuf response. | ||
| :type transcript: :class:`SpeechRecognitionAlternative` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| :param transcript: Instance of ``SpeechRecognitionAlternative`` | ||
| from protobuf. | ||
| :rtype: :class:`~Transcript` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| max_alternatives=2, | ||
| profanity_filter=True, | ||
| speech_context=self.HINTS) | ||
| with _Monkey(MUT, _USE_GAX=False): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| sample = Sample(source_uri=self.AUDIO_SOURCE_URI, encoding=encoding, | ||
| sample_rate=self.SAMPLE_RATE) | ||
| response = client.sync_recognize(sample) | ||
| with _Monkey(MUT, _USE_GAX=False): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
speech/unit_tests/test_client.py
Outdated
| encoding=speech.Encoding.FLAC, | ||
| sample_rate=self.SAMPLE_RATE) | ||
| client.sync_recognize(sample) | ||
| with self.assertRaises(IndexError): |
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.
| sample_rate=self.SAMPLE_RATE) | ||
| client.sync_recognize(sample) | ||
| with self.assertRaises(IndexError): | ||
| with _Monkey(MUT, _USE_GAX=False): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
speech/unit_tests/test_client.py
Outdated
|
|
||
|
|
||
| class _RecognitionConfig(object): | ||
| def __init__(self, *args, **kwargs): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
dhermes
left a comment
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.
Big 👍 on the refactor
| @@ -0,0 +1,76 @@ | |||
|
|
|||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
speech/google/cloud/speech/client.py
Outdated
| _USE_GAX = _HAVE_GAX and not _DISABLE_GAX | ||
|
|
||
|
|
||
| class Client(JSONClient): |
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.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| try: | ||
| from google.cloud.speech._gax import GAPICSpeechAPI | ||
| except ImportError: # pragma: NO COVER | ||
| _HAVE_GAX = False |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| """Helper for speech-related API calls.""" | ||
| if self._speech_api is None: | ||
| if self._use_gax: | ||
| self._speech_api = GAPICSpeechAPI() |
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.
speech/google/cloud/speech/client.py
Outdated
| profanity_filter, speech_context) | ||
|
|
||
| api_response = self.connection.api_request( | ||
| class JSONSpeechAPI(object): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
speech/unit_tests/test_client.py
Outdated
| self.assertFalse(operation.complete) | ||
| self.assertIsNone(operation.metadata) | ||
|
|
||
| def test_speech_api_with_gapic(self): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
speech/unit_tests/test_client.py
Outdated
| api = client.speech_api | ||
| self.assertIsInstance(api, _MockGAPICSpeechAPI) | ||
|
|
||
| def test_speech_api_without_gapic(self): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| api = client.speech_api | ||
| self.assertIsInstance(api, _MockJSONSpeechAPI) | ||
|
|
||
| def test_speech_api_preset(self): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
speech/google/cloud/speech/_gax.py
Outdated
|
|
||
|
|
||
| class GAPICSpeechAPI(object): | ||
| """Object to manage calls through GAPIC wrappers to the Speech API.""" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
speech/google/cloud/speech/_gax.py
Outdated
| uri=sample.source_uri) | ||
| api = self._gapic_api | ||
| api_response = api.sync_recognize(config=config, audio=audio) | ||
| results = api_response.results.pop() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
speech/setup.py
Outdated
| REQUIREMENTS = [ | ||
| 'google-cloud-core >= 0.20.0', | ||
| 'gapic-google-cloud-speech-v1beta1==0.11.1', | ||
| 'grpc-google-cloud-speech-v1beta1==0.11.1', |
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.
| credentials = _Credentials() | ||
| client = self._makeOne(credentials=credentials) | ||
| client = self._makeOne(credentials=credentials, use_gax=False) | ||
| client.connection = _Connection(RETURNED) |
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.
7e2e8f4 to
e24e96a
Compare
|
It looks like So I @dhermes I think I got everything you covered there. LMKWYT. |
|
Yeah I was trying something with testing. I just pushed that back up. |
d3d3ced to
9c3a578
Compare
|
Ok that should be resolved now. 'gapic-google-cloud-speech-v1beta1>=0.11.1,<0.12.0',
'grpc-google-cloud-speech-v1beta1>=0.11.1,<0.12.0', |
|
LGTM. |
29cb827 to
9031a0f
Compare
Add Speech GAPIC for sync_recognize.
Add Speech GAPIC for sync_recognize.
Add Speech GAPIC for sync_recognize.
Add Speech GAPIC for sync_recognize.
This adds GAPIC support to speech sync_recognize().