Skip to content

Using google.cloud.operation for GAPIC Speech async? #2629

Closed

Description

@daspecster

I've been struggling today with the right way to implement this.
I can't seem to make_secure_stub for speech.

This is the error I get...

File "/Users/daspecster/Documents/google/google-cloud-py-2/.tox/py27/lib/python2.7/site-packages/google_cloud_speech-0.20.0.dev0-py2.7.egg/google/cloud/speech/_gax.py", line 92, in async_recognize
    OPERATIONS_API_HOST)
  File "/Users/daspecster/Documents/google/google-cloud-py-2/.tox/py27/lib/python2.7/site-packages/google_cloud_core-0.20.0-py2.7.egg/google/cloud/_helpers.py", line 642, in make_secure_stub
    transport_creds = grpc.ssl_channel_credentials()
AttributeError: 'module' object has no attribute 'ssl_channel_credentials'

Example code:

        config = RecognitionConfig(
            encoding=sample.encoding, sample_rate=sample.sample_rate,
            language_code=language_code, max_alternatives=max_alternatives,
            profanity_filter=profanity_filter,
            speech_context=SpeechContext(phrases=speech_context))

        audio = RecognitionAudio(content=sample.content,
                                 uri=sample.source_uri)
        self._client._operations_stub = make_secure_stub(
            self._client.connection.credentials,
            DEFAULT_USER_AGENT,
            operations_grpc.OperationsStub,
            OPERATIONS_API_HOST)

        api = self._gapic_api
        operation = api.sync_recognize(config=config, audio=audio)
        return Operation.from_pb(operation, self._client)

Looking at the sample example it seems like the channel creation is different than it is in our _helpers.make_secure_stub

Activity

  1. daspecster commented on Oct 27, 2016

    @daspecster
    ContributorAuthor

    This seems to work though.

    ╰─$ .tox/py27/bin/python
    Python 2.7.10 (default, Oct 23 2015, 19:19:21)
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import grpc
    >>> grpc.ssl_channel_credentials()
    <grpc.ChannelCredentials object at 0x109463950>

    @bjwatson could something be messing up the grpc namespace in

        'gapic-google-cloud-speech-v1beta1 >= 0.11.1, < 0.12.0',
        'grpc-google-cloud-speech-v1beta1 >= 0.11.1, < 0.12.0',
    

    Also, @bjwatson, is gapic-google-longrunning ok to use or is it not really production ready yet?

  2. dhermes commented on Oct 27, 2016

    @dhermes
    Contributor

    @daspecster It seems like there is an old version of grpc? Also, you don't need make_secure_stub for Speech (not used in Pub/Sub or Logging).

    There is a "bug" in that we should pass credentials through, but you shouldn't worry about handling it to get Speech in.

  3. daspecster commented on Oct 27, 2016

    @daspecster
    ContributorAuthor

    @dhermes, Pub/Sub and Logging, don't use Operations AFAICT.
    A channel has to be made in order to make the OperationStub.
    https://github.com/GoogleCloudPlatform/python-docs-samples/blob/2da1c09b056798dd54be7106010f9d5610952bef/speech/grpc/transcribe_async.py#L32-L51

    I could just do that but that's not very DRY since we have it in core._helpers right?

  4. daspecster commented on Oct 27, 2016

    @daspecster
    ContributorAuthor

    Fixed with #2632.

  5. bjwatson commented on Oct 28, 2016

    @bjwatson

    @daspecster Yes, gapic-google-longrunning is okay to use, although I plan to merge it into the next release of google-gax (with the same path and module name).

    We are also designing a more convenient layer for you to use in the future that will sit on top of the gapic-google-longrunning code. I'll take a look at what you did for Speech, and want to discuss with you what pain points you had.

  6. daspecster commented on Oct 28, 2016

    @daspecster
    ContributorAuthor

    Ok sure! Thanks @bjwatson!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: speechIssues related to the Speech-to-Text API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions