Skip to content

Conversation

dizcology
Copy link
Member

Updating python code samples to use the GAPIC python client library for Speech API.

Merge only after the client library is released.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 5, 2017
@@ -1 +1 @@
google-cloud-speech==0.26.0
google-cloud-speech>=0.27.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer all requirements be ==, for maximum reproducibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

language_code='en-US')

# In practice requests should be a generator yielding chunks of audio data.
requests = [request]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be clearer if you only construct the StreamingRecognizeRequest within a generator. ie:

requests = (types.StreamingRecognizeRequest(audio_content=c) for c in [content])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

# [END audio_stream]


def listen_print_loop(results_gen):
def listen_print_loop(responses):
"""Iterates through server responses and prints them.

The results_gen passed is a generator that will block until a response
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should update the docstring as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

@jerjou jerjou self-assigned this Jul 12, 2017
Copy link
Contributor

@theacodes theacodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me, with a few nits.

audio = types.RecognitionAudio(content=content)

config = types.RecognitionConfig(
encoding='LINEAR16',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an enum for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is, but requires the additional import of from google.cloud.speech import enums. I was keeping it consistent with the existing samples.

language_code='en-US')

# In practice requests should be a generator yielding chunks of audio data.
requests = (types.StreamingRecognizeRequest(audio_content=c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a more descriptive variable name rather than c.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

encoding='LINEAR16',
sample_rate_hertz=RATE,
language_code=language_code)
streaming_config = types.StreamingRecognitionConfig(config=config,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: start a newline at the opening ( to avoid hanging indents like this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@theacodes
Copy link
Contributor

theacodes commented Jul 13, 2017 via email

@dizcology
Copy link
Member Author

in the current form of the GAPIC client library enums is its own module.

@theacodes
Copy link
Contributor

theacodes commented Jul 13, 2017 via email

Copy link
Contributor

@theacodes theacodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, but I can't merge it until the 0.27.0 version of the library is published. Have you run these tests locally?

@dizcology
Copy link
Member Author

I have tested with a client library provided to me to migrate these samples, but yes, let's wait after the package has been published and I have the chance to run the test against the published client.

@dizcology
Copy link
Member Author

@theacodes theacodes merged commit 218bc59 into GoogleCloudPlatform:master Jul 14, 2017
busunkim96 pushed a commit to busunkim96/python-speech that referenced this pull request Sep 1, 2020
…-samples#1012)

* Migrate quickstart to GAPIC client library

* Migrate transcribe to GAPIC client library

* Migrate transcribe_async to GAPIC client library

* Migrate transcribe_streaming to GAPIC client library

* clean up

* clean up

* Import from google.cloud.speech

* update transcribe samples

* import in alphabetic order

* remove unused variable

* use strings instead of enums

* restructure code

* comment on sreaming requests

* import style

* flake

* correct indent

* migrate transcribe_streaming_mic to gapic

* update google-cloud-speech version requirement

* addressing review comments

* at the end of the audio stream, put None to signal to the generator

* flake

* addressing github review comments

* add region tags for migration guide

* update README

* rst format

* bullet

* addressing PR review comments

* use enums

* remove a word
busunkim96 pushed a commit to googleapis/python-speech that referenced this pull request Sep 3, 2020
…-samples#1012)

* Migrate quickstart to GAPIC client library

* Migrate transcribe to GAPIC client library

* Migrate transcribe_async to GAPIC client library

* Migrate transcribe_streaming to GAPIC client library

* clean up

* clean up

* Import from google.cloud.speech

* update transcribe samples

* import in alphabetic order

* remove unused variable

* use strings instead of enums

* restructure code

* comment on sreaming requests

* import style

* flake

* correct indent

* migrate transcribe_streaming_mic to gapic

* update google-cloud-speech version requirement

* addressing review comments

* at the end of the audio stream, put None to signal to the generator

* flake

* addressing github review comments

* add region tags for migration guide

* update README

* rst format

* bullet

* addressing PR review comments

* use enums

* remove a word
telpirion pushed a commit that referenced this pull request Jan 13, 2023
* Migrate quickstart to GAPIC client library

* Migrate transcribe to GAPIC client library

* Migrate transcribe_async to GAPIC client library

* Migrate transcribe_streaming to GAPIC client library

* clean up

* clean up

* Import from google.cloud.speech

* update transcribe samples

* import in alphabetic order

* remove unused variable

* use strings instead of enums

* restructure code

* comment on sreaming requests

* import style

* flake

* correct indent

* migrate transcribe_streaming_mic to gapic

* update google-cloud-speech version requirement

* addressing review comments

* at the end of the audio stream, put None to signal to the generator

* flake

* addressing github review comments

* add region tags for migration guide

* update README

* rst format

* bullet

* addressing PR review comments

* use enums

* remove a word
dandhlee pushed a commit that referenced this pull request Feb 9, 2023
* Migrate quickstart to GAPIC client library

* Migrate transcribe to GAPIC client library

* Migrate transcribe_async to GAPIC client library

* Migrate transcribe_streaming to GAPIC client library

* clean up

* clean up

* Import from google.cloud.speech

* update transcribe samples

* import in alphabetic order

* remove unused variable

* use strings instead of enums

* restructure code

* comment on sreaming requests

* import style

* flake

* correct indent

* migrate transcribe_streaming_mic to gapic

* update google-cloud-speech version requirement

* addressing review comments

* at the end of the audio stream, put None to signal to the generator

* flake

* addressing github review comments

* add region tags for migration guide

* update README

* rst format

* bullet

* addressing PR review comments

* use enums

* remove a word
telpirion pushed a commit that referenced this pull request Mar 13, 2023
* Migrate quickstart to GAPIC client library

* Migrate transcribe to GAPIC client library

* Migrate transcribe_async to GAPIC client library

* Migrate transcribe_streaming to GAPIC client library

* clean up

* clean up

* Import from google.cloud.speech

* update transcribe samples

* import in alphabetic order

* remove unused variable

* use strings instead of enums

* restructure code

* comment on sreaming requests

* import style

* flake

* correct indent

* migrate transcribe_streaming_mic to gapic

* update google-cloud-speech version requirement

* addressing review comments

* at the end of the audio stream, put None to signal to the generator

* flake

* addressing github review comments

* add region tags for migration guide

* update README

* rst format

* bullet

* addressing PR review comments

* use enums

* remove a word
atulep pushed a commit to googleapis/google-cloud-python that referenced this pull request Apr 6, 2023
…-samples#1012)

* Migrate quickstart to GAPIC client library

* Migrate transcribe to GAPIC client library

* Migrate transcribe_async to GAPIC client library

* Migrate transcribe_streaming to GAPIC client library

* clean up

* clean up

* Import from google.cloud.speech

* update transcribe samples

* import in alphabetic order

* remove unused variable

* use strings instead of enums

* restructure code

* comment on sreaming requests

* import style

* flake

* correct indent

* migrate transcribe_streaming_mic to gapic

* update google-cloud-speech version requirement

* addressing review comments

* at the end of the audio stream, put None to signal to the generator

* flake

* addressing github review comments

* add region tags for migration guide

* update README

* rst format

* bullet

* addressing PR review comments

* use enums

* remove a word
atulep pushed a commit to googleapis/google-cloud-python that referenced this pull request Apr 6, 2023
…-samples#1012)

* Migrate quickstart to GAPIC client library

* Migrate transcribe to GAPIC client library

* Migrate transcribe_async to GAPIC client library

* Migrate transcribe_streaming to GAPIC client library

* clean up

* clean up

* Import from google.cloud.speech

* update transcribe samples

* import in alphabetic order

* remove unused variable

* use strings instead of enums

* restructure code

* comment on sreaming requests

* import style

* flake

* correct indent

* migrate transcribe_streaming_mic to gapic

* update google-cloud-speech version requirement

* addressing review comments

* at the end of the audio stream, put None to signal to the generator

* flake

* addressing github review comments

* add region tags for migration guide

* update README

* rst format

* bullet

* addressing PR review comments

* use enums

* remove a word
atulep pushed a commit to googleapis/google-cloud-python that referenced this pull request Apr 18, 2023
…-samples#1012)

* Migrate quickstart to GAPIC client library

* Migrate transcribe to GAPIC client library

* Migrate transcribe_async to GAPIC client library

* Migrate transcribe_streaming to GAPIC client library

* clean up

* clean up

* Import from google.cloud.speech

* update transcribe samples

* import in alphabetic order

* remove unused variable

* use strings instead of enums

* restructure code

* comment on sreaming requests

* import style

* flake

* correct indent

* migrate transcribe_streaming_mic to gapic

* update google-cloud-speech version requirement

* addressing review comments

* at the end of the audio stream, put None to signal to the generator

* flake

* addressing github review comments

* add region tags for migration guide

* update README

* rst format

* bullet

* addressing PR review comments

* use enums

* remove a word
parthea pushed a commit to googleapis/google-cloud-python that referenced this pull request Oct 22, 2023
…-samples#1012)

* Migrate quickstart to GAPIC client library

* Migrate transcribe to GAPIC client library

* Migrate transcribe_async to GAPIC client library

* Migrate transcribe_streaming to GAPIC client library

* clean up

* clean up

* Import from google.cloud.speech

* update transcribe samples

* import in alphabetic order

* remove unused variable

* use strings instead of enums

* restructure code

* comment on sreaming requests

* import style

* flake

* correct indent

* migrate transcribe_streaming_mic to gapic

* update google-cloud-speech version requirement

* addressing review comments

* at the end of the audio stream, put None to signal to the generator

* flake

* addressing github review comments

* add region tags for migration guide

* update README

* rst format

* bullet

* addressing PR review comments

* use enums

* remove a word
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants