| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
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.
Sorry, something went wrong.
| return cls(transcript['transcript'], transcript['confidence']) | ||
|
|
||
| @classmethod | ||
| def from_pb(cls, transcript): |
| def from_pb(cls, transcript): | ||
| """Factory: construct ``Transcript`` from protobuf response. | ||
|
|
||
| :type transcript: :class:`SpeechRecognitionAlternative` |
| :param transcript: Instance of ``SpeechRecognitionAlternative`` | ||
| from protobuf. | ||
|
|
||
| :rtype: :class:`~Transcript` |
| max_alternatives=2, | ||
| profanity_filter=True, | ||
| speech_context=self.HINTS) | ||
| with _Monkey(MUT, _USE_GAX=False): |
| 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): |
| encoding=speech.Encoding.FLAC, | ||
| sample_rate=self.SAMPLE_RATE) | ||
| client.sync_recognize(sample) | ||
| with self.assertRaises(IndexError): |
| sample_rate=self.SAMPLE_RATE) | ||
| client.sync_recognize(sample) | ||
| with self.assertRaises(IndexError): | ||
| with _Monkey(MUT, _USE_GAX=False): |
|
|
||
|
|
||
| class _RecognitionConfig(object): | ||
| def __init__(self, *args, **kwargs): |
There was a problem hiding this comment.
Big 👍 on the refactor
Sorry, something went wrong.
| @@ -0,0 +1,76 @@ | |||
|
|
|||
| _USE_GAX = _HAVE_GAX and not _DISABLE_GAX | ||
|
|
||
|
|
||
| class Client(JSONClient): |
| try: | ||
| from google.cloud.speech._gax import GAPICSpeechAPI | ||
| except ImportError: # pragma: NO COVER | ||
| _HAVE_GAX = False |
| """Helper for speech-related API calls.""" | ||
| if self._speech_api is None: | ||
| if self._use_gax: | ||
| self._speech_api = GAPICSpeechAPI() |
| profanity_filter, speech_context) | ||
|
|
||
| api_response = self.connection.api_request( | ||
| class JSONSpeechAPI(object): |
| self.assertFalse(operation.complete) | ||
| self.assertIsNone(operation.metadata) | ||
|
|
||
| def test_speech_api_with_gapic(self): |
| api = client.speech_api | ||
| self.assertIsInstance(api, _MockGAPICSpeechAPI) | ||
|
|
||
| def test_speech_api_without_gapic(self): |
| api = client.speech_api | ||
| self.assertIsInstance(api, _MockJSONSpeechAPI) | ||
|
|
||
| def test_speech_api_preset(self): |
|
|
||
|
|
||
| class GAPICSpeechAPI(object): | ||
| """Object to manage calls through GAPIC wrappers to the Speech API.""" |
| uri=sample.source_uri) | ||
| api = self._gapic_api | ||
| api_response = api.sync_recognize(config=config, audio=audio) | ||
| results = api_response.results.pop() |
| REQUIREMENTS = [ | ||
| 'google-cloud-core >= 0.20.0', | ||
| 'gapic-google-cloud-speech-v1beta1==0.11.1', | ||
| 'grpc-google-cloud-speech-v1beta1==0.11.1', |
| credentials = _Credentials() | ||
| client = self._makeOne(credentials=credentials) | ||
| client = self._makeOne(credentials=credentials, use_gax=False) | ||
| client.connection = _Connection(RETURNED) |
|
It looks like SpeechApi() does some credential digging. So I _Monkey'd SpeechApi back. @dhermes I think I got everything you covered there. LMKWYT. |
Sorry, something went wrong.
|
Yeah I was trying something with testing. I just pushed that back up. |
Sorry, something went wrong.
|
Ok yeah, that causes an error. |
Sorry, something went wrong.
|
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', |
Sorry, something went wrong.
|
LGTM. |
Sorry, something went wrong.
Add Speech GAPIC for sync_recognize.
Add Speech GAPIC for sync_recognize.
Add Speech GAPIC for sync_recognize.
Add Speech GAPIC for sync_recognize.
| Back | FazBrowse Home | New Git URL |
This adds GAPIC support to speech sync_recognize().