Skip to content

Add Speech GAPIC for sync_recognize. - #2615

Merged
daspecster merged 1 commit into
googleapis:masterfrom
daspecster:add-speech-sync-gapic
Oct 26, 2016
Merged

Add Speech GAPIC for sync_recognize.#2615
daspecster merged 1 commit into
googleapis:masterfrom
daspecster:add-speech-sync-gapic

Conversation

@daspecster

Copy link
Copy Markdown
Contributor

This adds GAPIC support to speech sync_recognize().

@daspecsterdaspecster added the api: speech Issues related to the Speech-to-Text API. label Oct 25, 2016
@googlebotgooglebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 25, 2016
@daspecsterdaspecster mentioned this pull request Oct 25, 2016
14 tasks

@dhermesdhermes left a comment

Copy link
Copy Markdown
Contributor

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.

def from_pb(cls, transcript):
"""Factory: construct ``Transcript`` from protobuf response.

:type transcript: :class:`SpeechRecognitionAlternative`

This comment was marked as spam.

:param transcript: Instance of ``SpeechRecognitionAlternative``
from protobuf.

:rtype: :class:`~Transcript`

This comment was marked as spam.

max_alternatives=2,
profanity_filter=True,
speech_context=self.HINTS)
with _Monkey(MUT, _USE_GAX=False):

This comment was marked as spam.

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.

Comment threadspeech/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.

This comment was marked as spam.

This comment was marked as spam.

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.

Comment threadspeech/unit_tests/test_client.py Outdated


class _RecognitionConfig(object):
def __init__(self, *args, **kwargs):

This comment was marked as spam.

@dhermesdhermes left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadspeech/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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

try:
from google.cloud.speech._gax import GAPICSpeechAPI
except ImportError: # pragma: NO COVER
_HAVE_GAX = False

This comment was marked as spam.

"""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.

This comment was marked as spam.

Comment threadspeech/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.

Comment threadspeech/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.

Comment threadspeech/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.

api = client.speech_api
self.assertIsInstance(api, _MockJSONSpeechAPI)

def test_speech_api_preset(self):

This comment was marked as spam.

Comment threadspeech/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.

Comment threadspeech/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.

Comment threadspeech/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.

This comment was marked as spam.

This comment was marked as spam.

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.

This comment was marked as spam.

@daspecster

Copy link
Copy Markdown
ContributorAuthor

It looks like SpeechApi() does some credential digging.
https://travis-ci.org/GoogleCloudPlatform/google-cloud-python/builds/170660357#L201-L212

So I _Monkey'd SpeechApi back.

@dhermes I think I got everything you covered there. LMKWYT.

@daspecster

Copy link
Copy Markdown
ContributorAuthor

Yeah I was trying something with testing. I just pushed that back up.

@daspecster

daspecster commented Oct 26, 2016

Copy link
Copy Markdown
ContributorAuthor

@daspecster
daspecsterforce-pushed the add-speech-sync-gapic branch 2 times, most recently from d3d3ced to 9c3a578CompareOctober 26, 2016 04:38
@daspecster

Copy link
Copy Markdown
ContributorAuthor

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',

@dhermes

Copy link
Copy Markdown
Contributor

LGTM.

@daspecster
daspecster merged commit 2e6ac38 into googleapis:masterOct 26, 2016
@daspecster
daspecster deleted the add-speech-sync-gapic branch October 26, 2016 05:25
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
atulep pushed a commit that referenced this pull request Apr 3, 2023
atulep pushed a commit that referenced this pull request Apr 18, 2023
parthea pushed a commit that referenced this pull request Oct 22, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: speechIssues related to the Speech-to-Text API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@daspecster@dhermes@bjwatson@tseaver@googlebot