Skip to content
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

Merged
merged 1 commit into from
Nov 3, 2016

Conversation

daspecster
Copy link
Contributor

@daspecster daspecster commented Nov 2, 2016

This will need #2661 in order for travis-ci to pass since I don't need metadata.py and operation.py after @dhermes refactored the core operation.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 and async_recognize()'s results.

There will be some updates for the gRPC version of sync_recognize() that will follow this as well.

@daspecster daspecster added the api: speech Issues related to the Speech-to-Text API. label Nov 2, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 2, 2016
@daspecster daspecster force-pushed the add-speech-async-gapic branch 2 times, most recently from 54b981b to eb08066 Compare November 2, 2016 04:10
@daspecster daspecster mentioned this pull request Nov 2, 2016
14 tasks
@@ -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.

@daspecster daspecster force-pushed the add-speech-async-gapic branch 2 times, most recently from 0ca8559 to bf805e3 Compare November 2, 2016 04:49
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.

OPERATIONS_API_HOST = 'speech.googleapis.com'

register_type(AsyncRecognizeMetadata)
register_type(AsyncRecognizeResponse)

This comment was marked as spam.

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

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.

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

This comment was marked as spam.

This comment was marked as spam.

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

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

This comment was marked as spam.

operation = client.async_recognize(sample)

self.assertFalse(operation.complete)
self.assertIsNone(operation.response)

This comment was marked as spam.

@@ -321,28 +321,40 @@ class _MockGAPICAlternative(object):
confidence = 0.95234356


class _MockGAPICMetadata(object):
type_url = None

This comment was marked as spam.

@daspecster
Copy link
Contributor Author

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

alternatives=[
cloud_speech_pb2.SpeechRecognitionAlternative(
transcript=transcript,
confidence=confidence,

This comment was marked as spam.


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.

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.

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.

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

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.

_results = None

def async_recognize(self, config, audio):
from google.longrunning.operations_pb2 import Operation

This comment was marked as spam.

"confidence": 0.9224355
}, {
"transcript": 'testing 4 5 6',
"confidence": 0.0123456

This comment was marked as spam.


with self.assertRaises(ValueError):
with _Monkey(MUT, SpeechApi=_MockGAPICSpeechAPI):
with _Monkey(_gax, SpeechApi=speech_api):

This comment was marked as spam.

self.assertEqual(results[1].transcript,
alternatives[1]['transcript'])
self.assertEqual(results[1].confidence,
alternatives[1]['confidence'])

This comment was marked as spam.

Copy link
Contributor

@dhermes dhermes left a 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

@daspecster
Copy link
Contributor Author

Travis has gone on strike again...

@daspecster
Copy link
Contributor Author

Finally travis ran this job. @dhermes, I'm merging(in 15minutes) since I got your suggestions in.

@dhermes
Copy link
Contributor

dhermes commented Nov 3, 2016

Feel free to merge now

@daspecster daspecster merged commit 3de5bc0 into googleapis:master Nov 3, 2016
@daspecster daspecster deleted the add-speech-async-gapic branch January 24, 2017 15:17
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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: speech Issues related to the Speech-to-Text API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants