Skip to content

Commit 413f8e7

Browse files
danoscarmiketheacodes
authored andcommitted
Re-generate library using speech/synth.py (googleapis#5915)
1 parent 427bd4c commit 413f8e7

File tree

17 files changed

+397
-138
lines changed

17 files changed

+397
-138
lines changed

speech/README.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
Python Client for Google Cloud Speech API (`Beta`_)
2-
====================================================
1+
Python Client for Cloud Speech API (`Beta`_)
2+
=============================================
33

4-
`Google Cloud Speech API`_: Google Cloud Speech API.
4+
`Cloud Speech API`_: Converts audio to text by applying powerful neural network models.
55

66
- `Client Library Documentation`_
77
- `Product Documentation`_
88

99
.. _Alpha: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst
10-
.. _Google Cloud Speech API: https://cloud.google.com/speech
11-
.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/speech/index.html
10+
.. _Cloud Speech API: https://cloud.google.com/speech
11+
.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/speech/usage.html
1212
.. _Product Documentation: https://cloud.google.com/speech
1313

1414
Quick Start
@@ -18,13 +18,13 @@ In order to use this library, you first need to go through the following steps:
1818

1919
1. `Select or create a Cloud Platform project.`_
2020
2. `Enable billing for your project.`_
21-
3. `Enable the Google Cloud Speech API.`_
21+
3. `Enable the Cloud Speech API.`_
2222
4. `Setup Authentication.`_
2323

2424
.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project
2525
.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project
26-
.. _Enable the Google Cloud Speech API.: https://cloud.google.com/speech
27-
.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/latest/core/auth.html
26+
.. _Enable the Cloud Speech API.: https://cloud.google.com/speech
27+
.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/stable/core/auth.html
2828

2929
Installation
3030
~~~~~~~~~~~~
@@ -86,12 +86,12 @@ SpeechClient
8686
Next Steps
8787
~~~~~~~~~~
8888

89-
- Read the `Client Library Documentation`_ for Google Cloud Speech API
89+
- Read the `Client Library Documentation`_ for Cloud Speech API
9090
API to see other available methods on the client.
91-
- Read the `Google Cloud Speech API Product documentation`_ to learn
91+
- Read the `Cloud Speech API Product documentation`_ to learn
9292
more about the product and see How-to Guides.
9393
- View this `repository’s main README`_ to see the full list of Cloud
9494
APIs that we cover.
9595

96-
.. _Google Cloud Speech API Product documentation: https://cloud.google.com/speech
97-
.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst
96+
.. _Cloud Speech API Product documentation: https://cloud.google.com/speech
97+
.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst

speech/docs/gapic/v1/api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Client for Google Cloud Speech API
2-
==================================
1+
Client for Cloud Speech API
2+
===========================
33

44
.. automodule:: google.cloud.speech_v1
55
:members:

speech/docs/gapic/v1/types.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Types for Google Cloud Speech API Client
2-
========================================
1+
Types for Cloud Speech API Client
2+
=================================
33

44
.. automodule:: google.cloud.speech_v1.types
55
:members:

speech/docs/index.rst

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,100 @@
1-
.. include:: /../asset/README.rst
1+
Python Client for Cloud Speech API (`Beta`_)
2+
=============================================
3+
4+
`Cloud Speech API`_: Converts audio to text by applying powerful neural network models.
5+
6+
- `Client Library Documentation`_
7+
- `Product Documentation`_
8+
9+
.. _Alpha: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst
10+
.. _Cloud Speech API: https://cloud.google.com/speech
11+
.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/speech/usage.html
12+
.. _Product Documentation: https://cloud.google.com/speech
13+
14+
Quick Start
15+
-----------
16+
17+
In order to use this library, you first need to go through the following steps:
18+
19+
1. `Select or create a Cloud Platform project.`_
20+
2. `Enable billing for your project.`_
21+
3. `Enable the Cloud Speech API.`_
22+
4. `Setup Authentication.`_
23+
24+
.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project
25+
.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project
26+
.. _Enable the Cloud Speech API.: https://cloud.google.com/speech
27+
.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/stable/core/auth.html
28+
29+
Installation
30+
~~~~~~~~~~~~
31+
32+
Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to
33+
create isolated Python environments. The basic problem it addresses is one of
34+
dependencies and versions, and indirectly permissions.
35+
36+
With `virtualenv`_, it's possible to install this library without needing system
37+
install permissions, and without clashing with the installed system
38+
dependencies.
39+
40+
.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/
41+
42+
43+
Mac/Linux
44+
^^^^^^^^^
45+
46+
.. code-block:: console
47+
48+
pip install virtualenv
49+
virtualenv <your-env>
50+
source <your-env>/bin/activate
51+
<your-env>/bin/pip install google-cloud-speech
52+
53+
54+
Windows
55+
^^^^^^^
56+
57+
.. code-block:: console
58+
59+
pip install virtualenv
60+
virtualenv <your-env>
61+
<your-env>\Scripts\activate
62+
<your-env>\Scripts\pip.exe install google-cloud-speech
63+
64+
Preview
65+
~~~~~~~
66+
67+
SpeechClient
68+
^^^^^^^^^^^^
69+
70+
.. code:: py
71+
72+
from google.cloud import speech_v1
73+
from google.cloud.speech_v1 import enums
74+
75+
client = speech_v1.SpeechClient()
76+
77+
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
78+
sample_rate_hertz = 44100
79+
language_code = 'en-US'
80+
config = {'encoding': encoding, 'sample_rate_hertz': sample_rate_hertz, 'language_code': language_code}
81+
uri = 'gs://bucket_name/file_name.flac'
82+
audio = {'uri': uri}
83+
84+
response = client.recognize(config, audio)
85+
86+
Next Steps
87+
~~~~~~~~~~
88+
89+
- Read the `Client Library Documentation`_ for Cloud Speech API
90+
API to see other available methods on the client.
91+
- Read the `Cloud Speech API Product documentation`_ to learn
92+
more about the product and see How-to Guides.
93+
- View this `repository’s main README`_ to see the full list of Cloud
94+
APIs that we cover.
95+
96+
.. _Cloud Speech API Product documentation: https://cloud.google.com/speech
97+
.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst
298

399
Api Reference
4100
-------------

speech/google/cloud/speech.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
#
13
# Copyright 2018 Google LLC
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");

speech/google/cloud/speech_v1/gapic/enums.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
#
13
# Copyright 2018 Google LLC
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,21 +21,31 @@
1921
class RecognitionConfig(object):
2022
class AudioEncoding(enum.IntEnum):
2123
"""
22-
Audio encoding of the data sent in the audio message. All encodings support
23-
only 1 channel (mono) audio. Only ``FLAC`` and ``WAV`` include a header that
24-
describes the bytes of audio that follow the header. The other encodings
25-
are raw audio bytes with no header.
24+
The encoding of the audio data sent in the request.
25+
26+
All encodings support only 1 channel (mono) audio.
2627
2728
For best results, the audio source should be captured and transmitted using
28-
a lossless encoding (``FLAC`` or ``LINEAR16``). Recognition accuracy may be
29-
reduced if lossy codecs, which include the other codecs listed in
30-
this section, are used to capture or transmit the audio, particularly if
31-
background noise is present.
29+
a lossless encoding (``FLAC`` or ``LINEAR16``). The accuracy of the speech
30+
recognition can be reduced if lossy codecs are used to capture or transmit
31+
audio, particularly if background noise is present. Lossy codecs include
32+
``MULAW``, ``AMR``, ``AMR_WB``, ``OGG_OPUS``, and ``SPEEX_WITH_HEADER_BYTE``.
33+
34+
The ``FLAC`` and ``WAV`` audio file formats include a header that describes the
35+
included audio content. You can request recognition for ``WAV`` files that
36+
contain either ``LINEAR16`` or ``MULAW`` encoded audio.
37+
If you send ``FLAC`` or ``WAV`` audio file format in
38+
your request, you do not need to specify an ``AudioEncoding``; the audio
39+
encoding format is determined from the file header. If you specify
40+
an ``AudioEncoding`` when you send send ``FLAC`` or ``WAV`` audio, the
41+
encoding configuration must match the encoding described in the audio
42+
header; otherwise the request returns an
43+
``google.rpc.Code.INVALID_ARGUMENT`` error code.
3244
3345
Attributes:
34-
ENCODING_UNSPECIFIED (int): Not specified. Will return result ``google.rpc.Code.INVALID_ARGUMENT``.
46+
ENCODING_UNSPECIFIED (int): Not specified.
3547
LINEAR16 (int): Uncompressed 16-bit signed little-endian samples (Linear PCM).
36-
FLAC (int): ```FLAC`` <https://xiph.org/flac/documentation.html>`_ (Free Lossless Audio
48+
FLAC (int): ``FLAC`` (Free Lossless Audio
3749
Codec) is the recommended encoding because it is
3850
lossless--therefore recognition is not compromised--and
3951
requires only about half the bandwidth of ``LINEAR16``. ``FLAC`` stream
@@ -44,7 +56,7 @@ class AudioEncoding(enum.IntEnum):
4456
AMR_WB (int): Adaptive Multi-Rate Wideband codec. ``sample_rate_hertz`` must be 16000.
4557
OGG_OPUS (int): Opus encoded audio frames in Ogg container
4658
(`OggOpus <https://wiki.xiph.org/OggOpus>`_).
47-
``sample_rate_hertz`` must be 16000.
59+
``sample_rate_hertz`` must be one of 8000, 12000, 16000, 24000, or 48000.
4860
SPEEX_WITH_HEADER_BYTE (int): Although the use of lossy encodings is not recommended, if a very low
4961
bitrate encoding is required, ``OGG_OPUS`` is highly preferred over
5062
Speex encoding. The `Speex <https://speex.org/>`_ encoding supported by

speech/google/cloud/speech_v1/gapic/speech_client.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
#
13
# Copyright 2018 Google LLC
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,6 +18,7 @@
1618
import pkg_resources
1719
import warnings
1820

21+
from google.oauth2 import service_account
1922
import google.api_core.gapic_v1.client_info
2023
import google.api_core.gapic_v1.config
2124
import google.api_core.gapic_v1.method
@@ -46,6 +49,27 @@ class SpeechClient(object):
4649
# find the method configuration in the client_config dictionary.
4750
_INTERFACE_NAME = 'google.cloud.speech.v1.Speech'
4851

52+
@classmethod
53+
def from_service_account_file(cls, filename, *args, **kwargs):
54+
"""Creates an instance of this client using the provided credentials
55+
file.
56+
57+
Args:
58+
filename (str): The path to the service account private key json
59+
file.
60+
args: Additional arguments to pass to the constructor.
61+
kwargs: Additional arguments to pass to the constructor.
62+
63+
Returns:
64+
SpeechClient: The constructed client.
65+
"""
66+
credentials = service_account.Credentials.from_service_account_file(
67+
filename)
68+
kwargs['credentials'] = credentials
69+
return cls(*args, **kwargs)
70+
71+
from_service_account_json = from_service_account_file
72+
4973
def __init__(self,
5074
transport=None,
5175
channel=None,
@@ -106,11 +130,12 @@ def __init__(self,
106130
'Received both a transport instance and '
107131
'credentials; these are mutually exclusive.')
108132
self.transport = transport
109-
self.transport = speech_grpc_transport.SpeechGrpcTransport(
110-
address=self.SERVICE_ADDRESS,
111-
channel=channel,
112-
credentials=credentials,
113-
)
133+
else:
134+
self.transport = speech_grpc_transport.SpeechGrpcTransport(
135+
address=self.SERVICE_ADDRESS,
136+
channel=channel,
137+
credentials=credentials,
138+
)
114139

115140
if client_info is None:
116141
client_info = (

speech/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
#
13
# Copyright 2018 Google LLC
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -70,7 +72,8 @@ def __init__(self,
7072
# Because this API includes a method that returns a
7173
# long-running operation (proto: google.longrunning.Operation),
7274
# instantiate an LRO client.
73-
self._operations_client = google.api_core.operations_v1.OperationsClient(channel)
75+
self._operations_client = google.api_core.operations_v1.OperationsClient(
76+
channel)
7477

7578
@classmethod
7679
def create_channel(cls,

0 commit comments

Comments
 (0)