Uh oh!
There was an error while loading. Please reload this page.
Basic implementation of Speech API. - #2344
Conversation
tseaver
left a comment
There was a problem hiding this comment.
Thank you very much for the patch -- it is very well done!
| bucket = client.get_bucket('<your-bucket-name>') | ||
| blob = bucket.blob('my-test-file.txt') | ||
| blob.upload_from_string('this is test content!') | ||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| At this moment we only support one method of the Speech API: | ||
| - `syncrecognize`_ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| - `syncrecognize`_ | ||
| Synchronous Recognize |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| --------------------- | ||
| The :meth:`~google.cloud.speech.Client.syncrecognize` method | ||
| does speech to text on a file and returns the text |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| The :meth:`~google.cloud.speech.Client.syncrecognize` method | ||
| does speech to text on a file and returns the text | ||
| as a :class:`list` of tuples dicts (each containing a transcript an a confidence value). |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| for param_name, param in required_params: | ||
| if param is None: | ||
| message = '%r cannot be None' % (param_name) | ||
| raise ValueError(message) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| if param is None: | ||
| message = '%r cannot be None' % (param_name) | ||
| raise ValueError(message) | ||
| config = dict(required_params) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| ('maxAlternatives', max_alternatives), | ||
| ('profanityFilter', profanity_filter)]: | ||
| if param is not None: | ||
| config[param_name] = param |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| sample_rate, | ||
| max_alternatives=2, | ||
| speech_context=hints) | ||
| self.assertEqual(speechrecognition_result[0]["transcript"], 'hello') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| with self.assertRaises(ValueError): | ||
| client.syncrecognize(None, None, None, None) | ||
| with self.assertRaises(ValueError): | ||
| client.syncrecognize(None, "uri", None, None) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Fematich
commented
Sep 18, 2016
Thank you for your feedback! I have implemented your suggestions, except for the additional examples with extra arguments in the docs. I will try to finish this tomorrow. |
| supported, which must be specified in the following | ||
| format: gs://bucket_name/object_name | ||
| :type content: bytes | ||
| :param content: Byte stream of audio. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| """Client to bundle configuration needed for API requests. | ||
| :type project: str | ||
| :param project: the project which the client acts on behalf of. Will be |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Basic client for Google Cloud Speech API.""" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| bucket = client.get_bucket('<your-bucket-name>') | ||
| blob = bucket.blob('my-test-file.txt') | ||
| blob.upload_from_string('this is test content!') | ||
| blob.upload_from_string('this is test content!') No newline at end of file |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| .. code-block:: python | ||
| >>> alternatives = client.sync_recognize(None,"gs://my-bucket/recording.flac", | ||
| ... "FLAC", 16000, max_alternatives=2): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| >>> for alternative in alternatives: | ||
| ... print('=' * 20) | ||
| ... print(' transcript: %s' % (alternative["transcript"],)) | ||
| ... print(' confidence: %s' % (alternative["confidence"],)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| ... print(' confidence: %s' % (alternative["confidence"],)) | ||
| ==================== | ||
| transcript: Hello, this is a test | ||
| confidence: 0.81 |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| """Google Cloud Speech API wrapper.""" | ||
| from google.cloud.speech.client import Client, Encoding |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| response = client.sync_recognize(_AUDIO_CONTENT, | ||
| encoding, | ||
| self.SAMPLE_RATE, | ||
| language_code="EN", |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| self.assertEqual(REQUEST, | ||
| client.connection._requested[0]['data']) | ||
| self.assertEqual(response[0]["transcript"], 'hello') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| }, | ||
| "audio": { | ||
| "content": _B64_AUDIO_CONTENT | ||
| } |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| self.assertEqual(REQUEST, | ||
| client.connection._requested[0]['data']) | ||
| self.assertEqual(response[0]["transcript"], 'hello') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| class _Credentials(object): | ||
| _scopes = ('https://www.googleapis.com/auth/cloud-platform') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
dhermes
commented
Sep 19, 2016
@Fematich Really great work! Especially impressed that you have Travis 100% green on your first try! |
Fematich
commented
Sep 20, 2016
I have updated the code (included source_uri again and updated formatting/unit_tests). |
| :type source_uri: str | ||
| :param source_uri: URI that points to a file that contains audio | ||
| data bytes as specified in RecognitionConfig. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| between 0 and 1. | ||
| """ | ||
| if (content is None) and (source_uri is None): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| raise ValueError('content and source_uri cannot be both equal to\ | ||
| None') | ||
| if (content is not None) and (source_uri is not None): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| """ | ||
| if (content is None) and (source_uri is None): | ||
| raise ValueError('content and source_uri cannot be both equal to\ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| None') | ||
| if (content is not None) and (source_uri is not None): | ||
| raise ValueError('content and source_uri cannot be both different from\ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| if sample_rate is None: | ||
| raise ValueError('sample_rate cannot be None') | ||
| if content is not None: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| } | ||
| SYNC_RECOGNIZE_EMPTY_RESPONSE = { | ||
| 'results': [] |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| import unittest | ||
| _AUDIO_SOURCE_URI = 'gs://sample-bucket/sample-recording.flac' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
tseaver
commented
Sep 21, 2016
dhermes
commented
Sep 21, 2016
I'm going to merge as-is. I'll send a PR addressing most of my concerns. Remaining issues outside of that PR will be: |
dhermes
commented
Sep 21, 2016
@Fematich Thanks for your great work! We decided to go ahead and merge to speed up the process. We'd like to get this library feature-complete ASAP so we didn't want the review cycle to slow us down on getting the first chunks in. From here, a person working on this library full-time will take it to the finish line. You were great! |
Fematich
commented
Sep 21, 2016
Thank you it was a pleasure :-)! |
Updates from #2344 for speech API.
Updates from googleapis#2344 for speech API.
PR created by the Librarian CLI to initialize a release. Merging this PR will auto trigger a release. Librarian Version: v0.7.0 Language Image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:c8612d3fffb3f6a32353b2d1abd16b61e87811866f7ec9d65b59b02eb452a620 <details><summary>google-cloud-bigquery: 3.39.0</summary> ## [3.39.0](googleapis/python-bigquery@v3.38.0...v3.39.0) (2025-12-12) ### Features * adds support for Python runtime 3.14 (#2322) ([6065e14c](googleapis/python-bigquery@6065e14c)) * Add ExternalRuntimeOptions to BigQuery routine (#2311) ([fa76e310](googleapis/python-bigquery@fa76e310)) ### Bug Fixes * remove ambiguous error codes from query retries (#2308) ([8bbd3d01](googleapis/python-bigquery@8bbd3d01)) * include `io.Base` in the `PathType` (#2323) ([b11e09cb](googleapis/python-bigquery@b11e09cb)) * honor custom `retry` in `job.result()` (#2302) ([e118b029](googleapis/python-bigquery@e118b029)) ### Documentation * remove experimental annotations from GA features (#2303) ([1f1f9d41](googleapis/python-bigquery@1f1f9d41)) </details> Co-authored-by: Daniel Sanche <d.sanche14@gmail.com>
I have made a basic implementation of Speech API.
This currently only supports
syncrecognizefrom the REST-API.I think I followed all the contribution guidelines:
However, this is my first contribution, so in case I missed something, please let me know and I will see how to fix it!