diff --git a/speech/README.rst b/speech/README.rst index eafcc174edbe..23f99ec9a141 100644 --- a/speech/README.rst +++ b/speech/README.rst @@ -1,14 +1,14 @@ -Python Client for Google Cloud Speech API (`Beta`_) -==================================================== +Python Client for Cloud Speech API (`Beta`_) +============================================= -`Google Cloud Speech API`_: Google Cloud Speech API. +`Cloud Speech API`_: Converts audio to text by applying powerful neural network models. - `Client Library Documentation`_ - `Product Documentation`_ .. _Alpha: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst -.. _Google Cloud Speech API: https://cloud.google.com/speech -.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/speech/index.html +.. _Cloud Speech API: https://cloud.google.com/speech +.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/speech/usage.html .. _Product Documentation: https://cloud.google.com/speech Quick Start @@ -18,13 +18,13 @@ In order to use this library, you first need to go through the following steps: 1. `Select or create a Cloud Platform project.`_ 2. `Enable billing for your project.`_ -3. `Enable the Google Cloud Speech API.`_ +3. `Enable the Cloud Speech API.`_ 4. `Setup Authentication.`_ .. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project .. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Enable the Google Cloud Speech API.: https://cloud.google.com/speech -.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/latest/core/auth.html +.. _Enable the Cloud Speech API.: https://cloud.google.com/speech +.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/stable/core/auth.html Installation ~~~~~~~~~~~~ @@ -86,12 +86,12 @@ SpeechClient Next Steps ~~~~~~~~~~ -- Read the `Client Library Documentation`_ for Google Cloud Speech API +- Read the `Client Library Documentation`_ for Cloud Speech API API to see other available methods on the client. -- Read the `Google Cloud Speech API Product documentation`_ to learn +- Read the `Cloud Speech API Product documentation`_ to learn more about the product and see How-to Guides. - View this `repository’s main README`_ to see the full list of Cloud APIs that we cover. -.. _Google Cloud Speech API Product documentation: https://cloud.google.com/speech -.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst +.. _Cloud Speech API Product documentation: https://cloud.google.com/speech +.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst \ No newline at end of file diff --git a/speech/docs/gapic/v1/api.rst b/speech/docs/gapic/v1/api.rst index 03ceab7b77c7..45658eda89a2 100644 --- a/speech/docs/gapic/v1/api.rst +++ b/speech/docs/gapic/v1/api.rst @@ -1,5 +1,5 @@ -Client for Google Cloud Speech API -================================== +Client for Cloud Speech API +=========================== .. automodule:: google.cloud.speech_v1 :members: diff --git a/speech/docs/gapic/v1/types.rst b/speech/docs/gapic/v1/types.rst index a403d5a4aa3d..6083c398def7 100644 --- a/speech/docs/gapic/v1/types.rst +++ b/speech/docs/gapic/v1/types.rst @@ -1,5 +1,5 @@ -Types for Google Cloud Speech API Client -======================================== +Types for Cloud Speech API Client +================================= .. automodule:: google.cloud.speech_v1.types :members: \ No newline at end of file diff --git a/speech/docs/index.rst b/speech/docs/index.rst index 46235ec288c9..6357c0b8e25e 100644 --- a/speech/docs/index.rst +++ b/speech/docs/index.rst @@ -1,4 +1,100 @@ -.. include:: /../asset/README.rst +Python Client for Cloud Speech API (`Beta`_) +============================================= + +`Cloud Speech API`_: Converts audio to text by applying powerful neural network models. + +- `Client Library Documentation`_ +- `Product Documentation`_ + +.. _Alpha: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst +.. _Cloud Speech API: https://cloud.google.com/speech +.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/speech/usage.html +.. _Product Documentation: https://cloud.google.com/speech + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. `Enable the Cloud Speech API.`_ +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Enable the Cloud Speech API.: https://cloud.google.com/speech +.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/stable/core/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + pip install virtualenv + virtualenv + source /bin/activate + /bin/pip install google-cloud-speech + + +Windows +^^^^^^^ + +.. code-block:: console + + pip install virtualenv + virtualenv + \Scripts\activate + \Scripts\pip.exe install google-cloud-speech + +Preview +~~~~~~~ + +SpeechClient +^^^^^^^^^^^^ + +.. code:: py + + from google.cloud import speech_v1 + from google.cloud.speech_v1 import enums + + client = speech_v1.SpeechClient() + + encoding = enums.RecognitionConfig.AudioEncoding.FLAC + sample_rate_hertz = 44100 + language_code = 'en-US' + config = {'encoding': encoding, 'sample_rate_hertz': sample_rate_hertz, 'language_code': language_code} + uri = 'gs://bucket_name/file_name.flac' + audio = {'uri': uri} + + response = client.recognize(config, audio) + +Next Steps +~~~~~~~~~~ + +- Read the `Client Library Documentation`_ for Cloud Speech API + API to see other available methods on the client. +- Read the `Cloud Speech API Product documentation`_ to learn + more about the product and see How-to Guides. +- View this `repository’s main README`_ to see the full list of Cloud + APIs that we cover. + +.. _Cloud Speech API Product documentation: https://cloud.google.com/speech +.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst Api Reference ------------- diff --git a/speech/google/cloud/speech.py b/speech/google/cloud/speech.py index f6be726b5ca4..fd511f736ef8 100644 --- a/speech/google/cloud/speech.py +++ b/speech/google/cloud/speech.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/speech/google/cloud/speech_v1/gapic/enums.py b/speech/google/cloud/speech_v1/gapic/enums.py index 225fbc8dcf05..e8fca9439e7e 100644 --- a/speech/google/cloud/speech_v1/gapic/enums.py +++ b/speech/google/cloud/speech_v1/gapic/enums.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,21 +21,31 @@ class RecognitionConfig(object): class AudioEncoding(enum.IntEnum): """ - Audio encoding of the data sent in the audio message. All encodings support - only 1 channel (mono) audio. Only ``FLAC`` and ``WAV`` include a header that - describes the bytes of audio that follow the header. The other encodings - are raw audio bytes with no header. + The encoding of the audio data sent in the request. + + All encodings support only 1 channel (mono) audio. For best results, the audio source should be captured and transmitted using - a lossless encoding (``FLAC`` or ``LINEAR16``). Recognition accuracy may be - reduced if lossy codecs, which include the other codecs listed in - this section, are used to capture or transmit the audio, particularly if - background noise is present. + a lossless encoding (``FLAC`` or ``LINEAR16``). The accuracy of the speech + recognition can be reduced if lossy codecs are used to capture or transmit + audio, particularly if background noise is present. Lossy codecs include + ``MULAW``, ``AMR``, ``AMR_WB``, ``OGG_OPUS``, and ``SPEEX_WITH_HEADER_BYTE``. + + The ``FLAC`` and ``WAV`` audio file formats include a header that describes the + included audio content. You can request recognition for ``WAV`` files that + contain either ``LINEAR16`` or ``MULAW`` encoded audio. + If you send ``FLAC`` or ``WAV`` audio file format in + your request, you do not need to specify an ``AudioEncoding``; the audio + encoding format is determined from the file header. If you specify + an ``AudioEncoding`` when you send send ``FLAC`` or ``WAV`` audio, the + encoding configuration must match the encoding described in the audio + header; otherwise the request returns an + ``google.rpc.Code.INVALID_ARGUMENT`` error code. Attributes: - ENCODING_UNSPECIFIED (int): Not specified. Will return result ``google.rpc.Code.INVALID_ARGUMENT``. + ENCODING_UNSPECIFIED (int): Not specified. LINEAR16 (int): Uncompressed 16-bit signed little-endian samples (Linear PCM). - FLAC (int): ```FLAC`` `_ (Free Lossless Audio + FLAC (int): ``FLAC`` (Free Lossless Audio Codec) is the recommended encoding because it is lossless--therefore recognition is not compromised--and requires only about half the bandwidth of ``LINEAR16``. ``FLAC`` stream @@ -44,7 +56,7 @@ class AudioEncoding(enum.IntEnum): AMR_WB (int): Adaptive Multi-Rate Wideband codec. ``sample_rate_hertz`` must be 16000. OGG_OPUS (int): Opus encoded audio frames in Ogg container (`OggOpus `_). - ``sample_rate_hertz`` must be 16000. + ``sample_rate_hertz`` must be one of 8000, 12000, 16000, 24000, or 48000. SPEEX_WITH_HEADER_BYTE (int): Although the use of lossy encodings is not recommended, if a very low bitrate encoding is required, ``OGG_OPUS`` is highly preferred over Speex encoding. The `Speex `_ encoding supported by diff --git a/speech/google/cloud/speech_v1/gapic/speech_client.py b/speech/google/cloud/speech_v1/gapic/speech_client.py index d2315011bcaa..e53c321a7bd4 100644 --- a/speech/google/cloud/speech_v1/gapic/speech_client.py +++ b/speech/google/cloud/speech_v1/gapic/speech_client.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +18,7 @@ import pkg_resources import warnings +from google.oauth2 import service_account import google.api_core.gapic_v1.client_info import google.api_core.gapic_v1.config import google.api_core.gapic_v1.method @@ -46,6 +49,27 @@ class SpeechClient(object): # find the method configuration in the client_config dictionary. _INTERFACE_NAME = 'google.cloud.speech.v1.Speech' + @classmethod + def from_service_account_file(cls, filename, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + SpeechClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs['credentials'] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + def __init__(self, transport=None, channel=None, @@ -106,11 +130,12 @@ def __init__(self, 'Received both a transport instance and ' 'credentials; these are mutually exclusive.') self.transport = transport - self.transport = speech_grpc_transport.SpeechGrpcTransport( - address=self.SERVICE_ADDRESS, - channel=channel, - credentials=credentials, - ) + else: + self.transport = speech_grpc_transport.SpeechGrpcTransport( + address=self.SERVICE_ADDRESS, + channel=channel, + credentials=credentials, + ) if client_info is None: client_info = ( diff --git a/speech/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py b/speech/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py index 107b64c2ee5f..122317a6bd69 100644 --- a/speech/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py +++ b/speech/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -70,7 +72,8 @@ def __init__(self, # Because this API includes a method that returns a # long-running operation (proto: google.longrunning.Operation), # instantiate an LRO client. - self._operations_client = google.api_core.operations_v1.OperationsClient(channel) + self._operations_client = google.api_core.operations_v1.OperationsClient( + channel) @classmethod def create_channel(cls, diff --git a/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py b/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py index b6da8ec2f3c7..3cd914848988 100644 --- a/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py +++ b/speech/google/cloud/speech_v1/proto/cloud_speech_pb2.py @@ -18,6 +18,7 @@ from google.longrunning import operations_pb2 as google_dot_longrunning_dot_operations__pb2 from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2 from google.protobuf import duration_pb2 as google_dot_protobuf_dot_duration__pb2 +from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2 from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 from google.rpc import status_pb2 as google_dot_rpc_dot_status__pb2 @@ -26,9 +27,9 @@ name='google/cloud/speech_v1/proto/cloud_speech.proto', package='google.cloud.speech.v1', syntax='proto3', - serialized_pb=_b('\n/google/cloud/speech_v1/proto/cloud_speech.proto\x12\x16google.cloud.speech.v1\x1a\x1cgoogle/api/annotations.proto\x1a#google/longrunning/operations.proto\x1a\x19google/protobuf/any.proto\x1a\x1egoogle/protobuf/duration.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x17google/rpc/status.proto\"\x86\x01\n\x10RecognizeRequest\x12\x39\n\x06\x63onfig\x18\x01 \x01(\x0b\x32).google.cloud.speech.v1.RecognitionConfig\x12\x37\n\x05\x61udio\x18\x02 \x01(\x0b\x32(.google.cloud.speech.v1.RecognitionAudio\"\x91\x01\n\x1bLongRunningRecognizeRequest\x12\x39\n\x06\x63onfig\x18\x01 \x01(\x0b\x32).google.cloud.speech.v1.RecognitionConfig\x12\x37\n\x05\x61udio\x18\x02 \x01(\x0b\x32(.google.cloud.speech.v1.RecognitionAudio\"\x99\x01\n\x19StreamingRecognizeRequest\x12N\n\x10streaming_config\x18\x01 \x01(\x0b\x32\x32.google.cloud.speech.v1.StreamingRecognitionConfigH\x00\x12\x17\n\raudio_content\x18\x02 \x01(\x0cH\x00\x42\x13\n\x11streaming_request\"\x8a\x01\n\x1aStreamingRecognitionConfig\x12\x39\n\x06\x63onfig\x18\x01 \x01(\x0b\x32).google.cloud.speech.v1.RecognitionConfig\x12\x18\n\x10single_utterance\x18\x02 \x01(\x08\x12\x17\n\x0finterim_results\x18\x03 \x01(\x08\"\xb4\x03\n\x11RecognitionConfig\x12I\n\x08\x65ncoding\x18\x01 \x01(\x0e\x32\x37.google.cloud.speech.v1.RecognitionConfig.AudioEncoding\x12\x19\n\x11sample_rate_hertz\x18\x02 \x01(\x05\x12\x15\n\rlanguage_code\x18\x03 \x01(\t\x12\x18\n\x10max_alternatives\x18\x04 \x01(\x05\x12\x18\n\x10profanity_filter\x18\x05 \x01(\x08\x12>\n\x0fspeech_contexts\x18\x06 \x03(\x0b\x32%.google.cloud.speech.v1.SpeechContext\x12 \n\x18\x65nable_word_time_offsets\x18\x08 \x01(\x08\"\x8b\x01\n\rAudioEncoding\x12\x18\n\x14\x45NCODING_UNSPECIFIED\x10\x00\x12\x0c\n\x08LINEAR16\x10\x01\x12\x08\n\x04\x46LAC\x10\x02\x12\t\n\x05MULAW\x10\x03\x12\x07\n\x03\x41MR\x10\x04\x12\n\n\x06\x41MR_WB\x10\x05\x12\x0c\n\x08OGG_OPUS\x10\x06\x12\x1a\n\x16SPEEX_WITH_HEADER_BYTE\x10\x07\" \n\rSpeechContext\x12\x0f\n\x07phrases\x18\x01 \x03(\t\"D\n\x10RecognitionAudio\x12\x11\n\x07\x63ontent\x18\x01 \x01(\x0cH\x00\x12\r\n\x03uri\x18\x02 \x01(\tH\x00\x42\x0e\n\x0c\x61udio_source\"U\n\x11RecognizeResponse\x12@\n\x07results\x18\x02 \x03(\x0b\x32/.google.cloud.speech.v1.SpeechRecognitionResult\"`\n\x1cLongRunningRecognizeResponse\x12@\n\x07results\x18\x02 \x03(\x0b\x32/.google.cloud.speech.v1.SpeechRecognitionResult\"\x9e\x01\n\x1cLongRunningRecognizeMetadata\x12\x18\n\x10progress_percent\x18\x01 \x01(\x05\x12.\n\nstart_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x34\n\x10last_update_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xb1\x02\n\x1aStreamingRecognizeResponse\x12!\n\x05\x65rror\x18\x01 \x01(\x0b\x32\x12.google.rpc.Status\x12\x43\n\x07results\x18\x02 \x03(\x0b\x32\x32.google.cloud.speech.v1.StreamingRecognitionResult\x12]\n\x11speech_event_type\x18\x04 \x01(\x0e\x32\x42.google.cloud.speech.v1.StreamingRecognizeResponse.SpeechEventType\"L\n\x0fSpeechEventType\x12\x1c\n\x18SPEECH_EVENT_UNSPECIFIED\x10\x00\x12\x1b\n\x17\x45ND_OF_SINGLE_UTTERANCE\x10\x01\"\x8d\x01\n\x1aStreamingRecognitionResult\x12J\n\x0c\x61lternatives\x18\x01 \x03(\x0b\x32\x34.google.cloud.speech.v1.SpeechRecognitionAlternative\x12\x10\n\x08is_final\x18\x02 \x01(\x08\x12\x11\n\tstability\x18\x03 \x01(\x02\"e\n\x17SpeechRecognitionResult\x12J\n\x0c\x61lternatives\x18\x01 \x03(\x0b\x32\x34.google.cloud.speech.v1.SpeechRecognitionAlternative\"w\n\x1cSpeechRecognitionAlternative\x12\x12\n\ntranscript\x18\x01 \x01(\t\x12\x12\n\nconfidence\x18\x02 \x01(\x02\x12/\n\x05words\x18\x03 \x03(\x0b\x32 .google.cloud.speech.v1.WordInfo\"t\n\x08WordInfo\x12-\n\nstart_time\x18\x01 \x01(\x0b\x32\x19.google.protobuf.Duration\x12+\n\x08\x65nd_time\x18\x02 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x0c\n\x04word\x18\x03 \x01(\t2\xa6\x03\n\x06Speech\x12\x81\x01\n\tRecognize\x12(.google.cloud.speech.v1.RecognizeRequest\x1a).google.cloud.speech.v1.RecognizeResponse\"\x1f\x82\xd3\xe4\x93\x02\x19\"\x14/v1/speech:recognize:\x01*\x12\x96\x01\n\x14LongRunningRecognize\x12\x33.google.cloud.speech.v1.LongRunningRecognizeRequest\x1a\x1d.google.longrunning.Operation\"*\x82\xd3\xe4\x93\x02$\"\x1f/v1/speech:longrunningrecognize:\x01*\x12\x7f\n\x12StreamingRecognize\x12\x31.google.cloud.speech.v1.StreamingRecognizeRequest\x1a\x32.google.cloud.speech.v1.StreamingRecognizeResponse(\x01\x30\x01\x42l\n\x1a\x63om.google.cloud.speech.v1B\x0bSpeechProtoP\x01Z\n\x0fspeech_contexts\x18\x06 \x03(\x0b\x32%.google.cloud.speech.v1.SpeechContext\x12 \n\x18\x65nable_word_time_offsets\x18\x08 \x01(\x08\x12$\n\x1c\x65nable_automatic_punctuation\x18\x0b \x01(\x08\x12\r\n\x05model\x18\r \x01(\t\x12\x14\n\x0cuse_enhanced\x18\x0e \x01(\x08\"\x8b\x01\n\rAudioEncoding\x12\x18\n\x14\x45NCODING_UNSPECIFIED\x10\x00\x12\x0c\n\x08LINEAR16\x10\x01\x12\x08\n\x04\x46LAC\x10\x02\x12\t\n\x05MULAW\x10\x03\x12\x07\n\x03\x41MR\x10\x04\x12\n\n\x06\x41MR_WB\x10\x05\x12\x0c\n\x08OGG_OPUS\x10\x06\x12\x1a\n\x16SPEEX_WITH_HEADER_BYTE\x10\x07\" \n\rSpeechContext\x12\x0f\n\x07phrases\x18\x01 \x03(\t\"D\n\x10RecognitionAudio\x12\x11\n\x07\x63ontent\x18\x01 \x01(\x0cH\x00\x12\r\n\x03uri\x18\x02 \x01(\tH\x00\x42\x0e\n\x0c\x61udio_source\"U\n\x11RecognizeResponse\x12@\n\x07results\x18\x02 \x03(\x0b\x32/.google.cloud.speech.v1.SpeechRecognitionResult\"`\n\x1cLongRunningRecognizeResponse\x12@\n\x07results\x18\x02 \x03(\x0b\x32/.google.cloud.speech.v1.SpeechRecognitionResult\"\x9e\x01\n\x1cLongRunningRecognizeMetadata\x12\x18\n\x10progress_percent\x18\x01 \x01(\x05\x12.\n\nstart_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x34\n\x10last_update_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xb1\x02\n\x1aStreamingRecognizeResponse\x12!\n\x05\x65rror\x18\x01 \x01(\x0b\x32\x12.google.rpc.Status\x12\x43\n\x07results\x18\x02 \x03(\x0b\x32\x32.google.cloud.speech.v1.StreamingRecognitionResult\x12]\n\x11speech_event_type\x18\x04 \x01(\x0e\x32\x42.google.cloud.speech.v1.StreamingRecognizeResponse.SpeechEventType\"L\n\x0fSpeechEventType\x12\x1c\n\x18SPEECH_EVENT_UNSPECIFIED\x10\x00\x12\x1b\n\x17\x45ND_OF_SINGLE_UTTERANCE\x10\x01\"\x8d\x01\n\x1aStreamingRecognitionResult\x12J\n\x0c\x61lternatives\x18\x01 \x03(\x0b\x32\x34.google.cloud.speech.v1.SpeechRecognitionAlternative\x12\x10\n\x08is_final\x18\x02 \x01(\x08\x12\x11\n\tstability\x18\x03 \x01(\x02\"e\n\x17SpeechRecognitionResult\x12J\n\x0c\x61lternatives\x18\x01 \x03(\x0b\x32\x34.google.cloud.speech.v1.SpeechRecognitionAlternative\"w\n\x1cSpeechRecognitionAlternative\x12\x12\n\ntranscript\x18\x01 \x01(\t\x12\x12\n\nconfidence\x18\x02 \x01(\x02\x12/\n\x05words\x18\x03 \x03(\x0b\x32 .google.cloud.speech.v1.WordInfo\"t\n\x08WordInfo\x12-\n\nstart_time\x18\x01 \x01(\x0b\x32\x19.google.protobuf.Duration\x12+\n\x08\x65nd_time\x18\x02 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x0c\n\x04word\x18\x03 \x01(\t2\xa9\x03\n\x06Speech\x12\x81\x01\n\tRecognize\x12(.google.cloud.speech.v1.RecognizeRequest\x1a).google.cloud.speech.v1.RecognizeResponse\"\x1f\x82\xd3\xe4\x93\x02\x19\"\x14/v1/speech:recognize:\x01*\x12\x96\x01\n\x14LongRunningRecognize\x12\x33.google.cloud.speech.v1.LongRunningRecognizeRequest\x1a\x1d.google.longrunning.Operation\"*\x82\xd3\xe4\x93\x02$\"\x1f/v1/speech:longrunningrecognize:\x01*\x12\x81\x01\n\x12StreamingRecognize\x12\x31.google.cloud.speech.v1.StreamingRecognizeRequest\x1a\x32.google.cloud.speech.v1.StreamingRecognizeResponse\"\x00(\x01\x30\x01\x42l\n\x1a\x63om.google.cloud.speech.v1B\x0bSpeechProtoP\x01Z`__. + base64). See `content limits `__. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1.StreamingRecognizeRequest) )) @@ -896,21 +918,27 @@ Attributes: encoding: - *Required* Encoding of audio data sent in all - ``RecognitionAudio`` messages. + Encoding of audio data sent in all ``RecognitionAudio`` + messages. This field is optional for ``FLAC`` and ``WAV`` + audio files and required for all other audio formats. For + details, see [AudioEncoding][google.cloud.speech.v1.Recognitio + nConfig.AudioEncoding]. sample_rate_hertz: - *Required* Sample rate in Hertz of the audio data sent in all + Sample rate in Hertz of the audio data sent in all ``RecognitionAudio`` messages. Valid values are: 8000-48000. 16000 is optimal. For best results, set the sampling rate of the audio source to 16000 Hz. If that's not possible, use the native sample rate of the audio source (instead of re- - sampling). + sampling). This field is optional for ``FLAC`` and ``WAV`` + audio files and required for all other audio formats. For + details, see [AudioEncoding][google.cloud.speech.v1.Recognitio + nConfig.AudioEncoding]. language_code: *Required* The language of the supplied audio as a `BCP-47 `__ language - tag. Example: "en-US". See `Language Support - `__ for a list - of the currently supported language codes. + tag. Example: "en-US". See `Language Support `__ for a list of the currently supported + language codes. max_alternatives: *Optional* Maximum number of recognition hypotheses to be returned. Specifically, the maximum number of @@ -926,13 +954,63 @@ "f\*\*\*". If set to ``false`` or omitted, profanities won't be filtered out. speech_contexts: - *Optional* A means to provide context to assist the speech - recognition. + *Optional* array of + [SpeechContext][google.cloud.speech.v1.SpeechContext]. A means + to provide context to assist the speech recognition. For more + information, see `Phrase Hints `__. enable_word_time_offsets: *Optional* If ``true``, the top result includes a list of words and the start and end time offsets (timestamps) for those words. If ``false``, no word-level time offset information is returned. The default is ``false``. + enable_automatic_punctuation: + *Optional* If 'true', adds punctuation to recognition result + hypotheses. This feature is only available in select + languages. Setting this for requests in other languages has no + effect at all. The default 'false' value does not add + punctuation to result hypotheses. Note: This is currently + offered as an experimental service, complimentary to all + users. In the future this may be exclusively available as a + premium feature. + model: + *Optional* Which model to select for the given request. Select + the model best suited to your domain to get best results. If a + model is not explicitly specified, then we auto-select a model + based on the parameters in the RecognitionConfig. .. raw:: + html .. raw:: html :: + .. + raw:: html .. raw:: html :: + .. + raw:: html .. raw:: html :: + .. raw:: html .. raw:: + html :: + .. + raw:: html .. raw:: html :: + .. raw:: + html .. raw:: html
Model Description
command_and_search Best for + short queries such as voice commands or voice search.
phone_call Best for audio that + originated from a phone call (typically recorded at an + 8khz sampling rate).
videoBest for audio that originated from from video or includes + multiple speakers. Ideally the audio is recorded at a + 16khz or greater sampling rate. This is a premium + model that costs more than the standard rate.
default Best for audio that is + not one of the specific audio models. For example, + long-form audio. Ideally the audio is high-fidelity, + recorded at a 16khz or greater sampling rate.
+ use_enhanced: + *Optional* Set to true to use an enhanced model for speech + recognition. You must also set the ``model`` field to a valid, + enhanced model. If ``use_enhanced`` is set to true and the + ``model`` field is not set, then ``use_enhanced`` is ignored. + If ``use_enhanced`` is true and an enhanced version of the + specified model does not exist, then the speech is recognized + using the standard version of the specified model. Enhanced + speech models require that you opt-in to data logging using + instructions in the `documentation `__. If you set ``use_enhanced`` to true and you + have not enabled audio logging, then you will receive an + error. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1.RecognitionConfig) )) @@ -954,8 +1032,7 @@ specific words and phrases, for example, if specific commands are typically spoken by the user. This can also be used to add additional words to the vocabulary of the recognizer. See - `usage limits - `__. + `usage limits `__. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1.SpeechContext) )) @@ -969,7 +1046,7 @@ ``RecognitionConfig``. Either ``content`` or ``uri`` must be supplied. Supplying both or neither returns [google.rpc.Code.INVALID\_ARGUMENT][google.rpc.Code.INVALID\_ARGUMENT]. - See `audio limits `__. + See `content limits `__. Attributes: @@ -983,13 +1060,14 @@ representations use base64. uri: URI that points to a file that contains audio data bytes as - specified in ``RecognitionConfig``. Currently, only Google - Cloud Storage URIs are supported, which must be specified in - the following format: ``gs://bucket_name/object_name`` (other - URI formats return [google.rpc.Code.INVALID\_ARGUMENT][google. - rpc.Code.INVALID\_ARGUMENT]). For more information, see - `Request URIs - `__. + specified in ``RecognitionConfig``. The file must not be + compressed (for example, gzip). Currently, only Google Cloud + Storage URIs are supported, which must be specified in the + following format: ``gs://bucket_name/object_name`` (other URI + formats return [google.rpc.Code.INVALID\_ARGUMENT][google.rpc. + Code.INVALID\_ARGUMENT]). For more information, see `Request + URIs `__. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1.RecognitionAudio) )) @@ -1006,7 +1084,7 @@ Attributes: results: - *Output-only* Sequential list of transcription results + Output only. Sequential list of transcription results corresponding to sequential portions of audio. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1.RecognizeResponse) @@ -1027,7 +1105,7 @@ Attributes: results: - *Output-only* Sequential list of transcription results + Output only. Sequential list of transcription results corresponding to sequential portions of audio. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1.LongRunningRecognizeResponse) @@ -1115,17 +1193,17 @@ Attributes: error: - *Output-only* If set, returns a + Output only. If set, returns a [google.rpc.Status][google.rpc.Status] message that specifies the error for the operation. results: - *Output-only* This repeated list contains zero or more results + Output only. This repeated list contains zero or more results that correspond to consecutive portions of the audio currently - being processed. It contains zero or more ``is_final=false`` - results followed by zero or one ``is_final=true`` result (the - newly settled portion). + being processed. It contains zero or one ``is_final=true`` + result (the newly settled portion), followed by zero or more + ``is_final=false`` results (the interim results). speech_event_type: - *Output-only* Indicates the type of speech event. + Output only. Indicates the type of speech event. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1.StreamingRecognizeResponse) )) @@ -1141,23 +1219,25 @@ Attributes: alternatives: - *Output-only* May contain one or more recognition hypotheses - (up to the maximum specified in ``max_alternatives``). + Output only. May contain one or more recognition hypotheses + (up to the maximum specified in ``max_alternatives``). These + alternatives are ordered in terms of accuracy, with the top + (first) alternative being the most probable, as ranked by the + recognizer. is_final: - *Output-only* If ``false``, this - ``StreamingRecognitionResult`` represents an interim result - that may change. If ``true``, this is the final time the - speech service will return this particular - ``StreamingRecognitionResult``, the recognizer will not return - any further hypotheses for this portion of the transcript and - corresponding audio. + Output only. If ``false``, this ``StreamingRecognitionResult`` + represents an interim result that may change. If ``true``, + this is the final time the speech service will return this + particular ``StreamingRecognitionResult``, the recognizer will + not return any further hypotheses for this portion of the + transcript and corresponding audio. stability: - *Output-only* An estimate of the likelihood that the - recognizer will not change its guess about this interim - result. Values range from 0.0 (completely unstable) to 1.0 - (completely stable). This field is only provided for interim - results (``is_final=false``). The default of 0.0 is a sentinel - value indicating ``stability`` was not set. + Output only. An estimate of the likelihood that the recognizer + will not change its guess about this interim result. Values + range from 0.0 (completely unstable) to 1.0 (completely + stable). This field is only provided for interim results + (``is_final=false``). The default of 0.0 is a sentinel value + indicating ``stability`` was not set. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1.StreamingRecognitionResult) )) @@ -1172,7 +1252,7 @@ Attributes: alternatives: - *Output-only* May contain one or more recognition hypotheses + Output only. May contain one or more recognition hypotheses (up to the maximum specified in ``max_alternatives``). These alternatives are ordered in terms of accuracy, with the top (first) alternative being the most probable, as ranked by the @@ -1191,19 +1271,19 @@ Attributes: transcript: - *Output-only* Transcript text representing the words that the + Output only. Transcript text representing the words that the user spoke. confidence: - *Output-only* The confidence estimate between 0.0 and 1.0. A + Output only. The confidence estimate between 0.0 and 1.0. A higher number indicates an estimated greater likelihood that - the recognized words are correct. This field is typically - provided only for the top hypothesis, and only for - ``is_final=true`` results. Clients should not rely on the - ``confidence`` field as it is not guaranteed to be accurate or - consistent. The default of 0.0 is a sentinel value indicating - ``confidence`` was not set. + the recognized words are correct. This field is set only for + the top alternative of a non-streaming result or, of a + streaming result where ``is_final=true``. This field is not + guaranteed to be accurate and users should not rely on it to + be always provided. The default of 0.0 is a sentinel value + indicating ``confidence`` was not set. words: - *Output-only* A list of word-specific information for each + Output only. A list of word-specific information for each recognized word. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1.SpeechRecognitionAlternative) @@ -1214,26 +1294,24 @@ DESCRIPTOR = _WORDINFO, __module__ = 'google.cloud.speech_v1.proto.cloud_speech_pb2' , - __doc__ = """Word-specific information for recognized words. Word information is only - included in the response when certain request parameters are set, such - as ``enable_word_time_offsets``. + __doc__ = """Word-specific information for recognized words. Attributes: start_time: - *Output-only* Time offset relative to the beginning of the + Output only. Time offset relative to the beginning of the audio, and corresponding to the start of the spoken word. This field is only set if ``enable_word_time_offsets=true`` and only in the top hypothesis. This is an experimental feature and the accuracy of the time offset can vary. end_time: - *Output-only* Time offset relative to the beginning of the + Output only. Time offset relative to the beginning of the audio, and corresponding to the end of the spoken word. This field is only set if ``enable_word_time_offsets=true`` and only in the top hypothesis. This is an experimental feature and the accuracy of the time offset can vary. word: - *Output-only* The word corresponding to this set of + Output only. The word corresponding to this set of information. """, # @@protoc_insertion_point(class_scope:google.cloud.speech.v1.WordInfo) @@ -1250,8 +1328,8 @@ file=DESCRIPTOR, index=0, options=None, - serialized_start=2525, - serialized_end=2947, + serialized_start=2629, + serialized_end=3054, methods=[ _descriptor.MethodDescriptor( name='Recognize', diff --git a/speech/google/cloud/speech_v1/types.py b/speech/google/cloud/speech_v1/types.py index 78a660a3fc4a..c6ea1c9bc04e 100644 --- a/speech/google/cloud/speech_v1/types.py +++ b/speech/google/cloud/speech_v1/types.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/speech/google/cloud/speech_v1p1beta1/gapic/enums.py b/speech/google/cloud/speech_v1p1beta1/gapic/enums.py index 7fe2c8f69459..ba58fb015bbc 100644 --- a/speech/google/cloud/speech_v1p1beta1/gapic/enums.py +++ b/speech/google/cloud/speech_v1p1beta1/gapic/enums.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/speech/google/cloud/speech_v1p1beta1/gapic/speech_client.py b/speech/google/cloud/speech_v1p1beta1/gapic/speech_client.py index 111e0899aad5..45f578180751 100644 --- a/speech/google/cloud/speech_v1p1beta1/gapic/speech_client.py +++ b/speech/google/cloud/speech_v1p1beta1/gapic/speech_client.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +18,7 @@ import pkg_resources import warnings +from google.oauth2 import service_account import google.api_core.gapic_v1.client_info import google.api_core.gapic_v1.config import google.api_core.gapic_v1.method @@ -46,6 +49,27 @@ class SpeechClient(object): # find the method configuration in the client_config dictionary. _INTERFACE_NAME = 'google.cloud.speech.v1p1beta1.Speech' + @classmethod + def from_service_account_file(cls, filename, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + SpeechClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs['credentials'] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + def __init__(self, transport=None, channel=None, @@ -106,11 +130,12 @@ def __init__(self, 'Received both a transport instance and ' 'credentials; these are mutually exclusive.') self.transport = transport - self.transport = speech_grpc_transport.SpeechGrpcTransport( - address=self.SERVICE_ADDRESS, - channel=channel, - credentials=credentials, - ) + else: + self.transport = speech_grpc_transport.SpeechGrpcTransport( + address=self.SERVICE_ADDRESS, + channel=channel, + credentials=credentials, + ) if client_info is None: client_info = ( diff --git a/speech/google/cloud/speech_v1p1beta1/gapic/transports/speech_grpc_transport.py b/speech/google/cloud/speech_v1p1beta1/gapic/transports/speech_grpc_transport.py index 8029a73c6f50..2d229c20bece 100644 --- a/speech/google/cloud/speech_v1p1beta1/gapic/transports/speech_grpc_transport.py +++ b/speech/google/cloud/speech_v1p1beta1/gapic/transports/speech_grpc_transport.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -70,7 +72,8 @@ def __init__(self, # Because this API includes a method that returns a # long-running operation (proto: google.longrunning.Operation), # instantiate an LRO client. - self._operations_client = google.api_core.operations_v1.OperationsClient(channel) + self._operations_client = google.api_core.operations_v1.OperationsClient( + channel) @classmethod def create_channel(cls, diff --git a/speech/google/cloud/speech_v1p1beta1/types.py b/speech/google/cloud/speech_v1p1beta1/types.py index 4b4cec915997..083452329a34 100644 --- a/speech/google/cloud/speech_v1p1beta1/types.py +++ b/speech/google/cloud/speech_v1p1beta1/types.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/speech/synth.py b/speech/synth.py index 8322b9013b6e..94f3e8206c8b 100644 --- a/speech/synth.py +++ b/speech/synth.py @@ -63,6 +63,11 @@ 'Google Cloud Speech API (`Beta`_)') +s.replace( + ['README.rst', 'docs/index.rst'], + '`Alpha`', '`Beta`') + + # Fix bad reference to operations_v1 s.replace( '**/gapic/**/*_transport.py', diff --git a/speech/tests/unit/gapic/v1/test_speech_client_v1.py b/speech/tests/unit/gapic/v1/test_speech_client_v1.py index f129d4f8b0b9..293d32b632df 100644 --- a/speech/tests/unit/gapic/v1/test_speech_client_v1.py +++ b/speech/tests/unit/gapic/v1/test_speech_client_v1.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/speech/tests/unit/gapic/v1p1beta1/test_speech_client_v1p1beta1.py b/speech/tests/unit/gapic/v1p1beta1/test_speech_client_v1p1beta1.py index 16e2420f6eaa..b291589af5bd 100644 --- a/speech/tests/unit/gapic/v1p1beta1/test_speech_client_v1p1beta1.py +++ b/speech/tests/unit/gapic/v1p1beta1/test_speech_client_v1p1beta1.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License");