Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-generate library using speech/synth.py #5915

Merged
merged 2 commits into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions speech/README.rst
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
~~~~~~~~~~~~
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions speech/docs/gapic/v1/api.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Client for Google Cloud Speech API
==================================
Client for Cloud Speech API
===========================

.. automodule:: google.cloud.speech_v1
:members:
Expand Down
4 changes: 2 additions & 2 deletions speech/docs/gapic/v1/types.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Types for Google Cloud Speech API Client
========================================
Types for Cloud Speech API Client
=================================

.. automodule:: google.cloud.speech_v1.types
:members:
98 changes: 97 additions & 1 deletion speech/docs/index.rst
Original file line number Diff line number Diff line change
@@ -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 <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install google-cloud-speech


Windows
^^^^^^^

.. code-block:: console

pip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\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
-------------
Expand Down
2 changes: 2 additions & 0 deletions speech/google/cloud/speech.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
34 changes: 23 additions & 11 deletions speech/google/cloud/speech_v1/gapic/enums.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -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`` <https://xiph.org/flac/documentation.html>`_ (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
Expand All @@ -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 <https://wiki.xiph.org/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 <https://speex.org/>`_ encoding supported by
Expand Down
35 changes: 30 additions & 5 deletions speech/google/cloud/speech_v1/gapic/speech_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -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,
Expand Down
Loading