Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# Generated by synthtool. DO NOT EDIT!
[flake8]
ignore = E203, E266, E501, W503, F401, F841
ignore = E203, E266, E501, W503
exclude =
# Exclude generated code.
**/proto/**
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pip-log.txt
# Built documentation
docs/_build
bigquery/docs/generated
docs.metadata

# Virtual environment
env/
Expand All @@ -58,4 +57,4 @@ system_tests/local_test_setup

# Make sure a generated file isn't accidentally committed.
pylintrc
pylintrc.test
pylintrc.test
22 changes: 2 additions & 20 deletions .kokoro/docs/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ action {
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"

# Use the trampoline script to run in docker.
build_file: "python-texttospeech/.kokoro/trampoline_v2.sh"
build_file: "python-texttospeech/.kokoro/trampoline.sh"

# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/python-lib-docs"
value: "gcr.io/cloud-devrel-kokoro-resources/python-multi"
}

env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/python-texttospeech/.kokoro/publish-docs.sh"
Expand All @@ -29,23 +28,6 @@ env_vars: {
value: "docs-staging"
}

env_vars: {
key: "V2_STAGING_BUCKET"
value: "docs-staging-v2-staging"
}

# It will upload the docker image after successful builds.
env_vars: {
key: "TRAMPOLINE_IMAGE_UPLOAD"
value: "true"
}

# It will always build the docker image.
env_vars: {
key: "TRAMPOLINE_DOCKERFILE"
value: ".kokoro/docker/docs/Dockerfile"
}

# Fetch the token needed for reporting release status to GitHub
before_action {
fetch_keystore {
Expand Down
40 changes: 15 additions & 25 deletions .kokoro/publish-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,26 @@ set -eo pipefail
# Disable buffering, so that the logs stream through.
export PYTHONUNBUFFERED=1

export PATH="${HOME}/.local/bin:${PATH}"
cd github/python-texttospeech

# Remove old nox
python3.6 -m pip uninstall --yes --quiet nox-automation

# Install nox
python3 -m pip install --user --upgrade --quiet nox
python3 -m nox --version
python3.6 -m pip install --upgrade --quiet nox
python3.6 -m nox --version

# build docs
nox -s docs

python3 -m pip install --user gcp-docuploader
python3 -m pip install gcp-docuploader

# install a json parser
sudo apt-get update
sudo apt-get -y install software-properties-common
sudo add-apt-repository universe
sudo apt-get update
sudo apt-get -y install jq

# create metadata
python3 -m docuploader create-metadata \
Expand All @@ -42,24 +52,4 @@ python3 -m docuploader create-metadata \
cat docs.metadata

# upload docs
python3 -m docuploader upload docs/_build/html --metadata-file docs.metadata --staging-bucket "${STAGING_BUCKET}"


# docfx yaml files
nox -s docfx

# create metadata.
python3 -m docuploader create-metadata \
--name=$(jq --raw-output '.name // empty' .repo-metadata.json) \
--version=$(python3 setup.py --version) \
--language=$(jq --raw-output '.language // empty' .repo-metadata.json) \
--distribution-name=$(python3 setup.py --name) \
--product-page=$(jq --raw-output '.product_documentation // empty' .repo-metadata.json) \
--github-repository=$(jq --raw-output '.repo // empty' .repo-metadata.json) \
--issue-tracker=$(jq --raw-output '.issue_tracker // empty' .repo-metadata.json) \
--serving-path="/python/docs/reference/$(jq --raw-output '.name // empty' .repo-metadata.json)/$(jq --raw-output '.distribution_name // empty' .repo-metadata.json)/latest"

cat docs.metadata

# upload docs
python3 -m docuploader upload docs/_build/html/docfx_yaml --metadata-file docs.metadata --destination-prefix docfx --staging-bucket "${V2_STAGING_BUCKET}"
python3 -m docuploader upload docs/_build/html --metadata-file docs.metadata --staging-bucket docs-staging
4 changes: 0 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath(".."))

# For plugins that can not read conf.py.
sys.path.insert(0, os.path.abspath("."))


__version__ = ""

# -- General configuration ------------------------------------------------
Expand Down
70 changes: 42 additions & 28 deletions google/cloud/texttospeech_v1/services/text_to_speech/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,27 @@ def __init__(
# instance provides an extensibility point for unusual situations.
if isinstance(transport, TextToSpeechTransport):
# transport is a TextToSpeechTransport instance.
if credentials:
if credentials or client_options.credentials_file:
raise ValueError(
"When providing a transport instance, "
"provide its credentials directly."
)
if client_options.scopes:
raise ValueError(
"When providing a transport instance, "
"provide its scopes directly."
)
self._transport = transport
else:
Transport = type(self).get_transport_class(transport)
self._transport = Transport(
credentials=credentials,
credentials_file=client_options.credentials_file,
host=client_options.api_endpoint,
scopes=client_options.scopes,
api_mtls_endpoint=client_options.api_endpoint,
client_cert_source=client_options.client_cert_source,
quota_project_id=client_options.quota_project_id,
)

def list_voices(
Expand All @@ -228,11 +236,11 @@ def list_voices(
language tag. If specified, the ListVoices call will
only return voices that can be used to synthesize this
language_code. E.g. when specifying "en-NZ", you will
get supported "en-\*" voices; when specifying "no", you
will get supported "no-\*" (Norwegian) and "nb-*"
get supported "en-*" voices; when specifying "no", you
will get supported "no-*" (Norwegian) and "nb-*"
(Norwegian Bokmal) voices; specifying "zh" will also get
supported "cmn-*" voices; specifying "zh-hk" will also
get supported "yue-\*" voices.
get supported "yue-*" voices.
This corresponds to the ``language_code`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
Expand All @@ -252,25 +260,29 @@ def list_voices(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([language_code]):
has_flattened_params = any([language_code])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

request = cloud_tts.ListVoicesRequest(request)
# Minor optimization to avoid making a copy if the user passes
# in a cloud_tts.ListVoicesRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, cloud_tts.ListVoicesRequest):
request = cloud_tts.ListVoicesRequest(request)

# If we have keyword arguments corresponding to fields on the
# request, apply these.
# If we have keyword arguments corresponding to fields on the
# request, apply these.

if language_code is not None:
request.language_code = language_code
if language_code is not None:
request.language_code = language_code

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method.wrap_method(
self._transport.list_voices, default_timeout=None, client_info=_client_info
)
rpc = self._transport._wrapped_methods[self._transport.list_voices]

# Send the request.
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata)
Expand Down Expand Up @@ -330,31 +342,33 @@ def synthesize_speech(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([input, voice, audio_config]):
has_flattened_params = any([input, voice, audio_config])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

request = cloud_tts.SynthesizeSpeechRequest(request)
# Minor optimization to avoid making a copy if the user passes
# in a cloud_tts.SynthesizeSpeechRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, cloud_tts.SynthesizeSpeechRequest):
request = cloud_tts.SynthesizeSpeechRequest(request)

# If we have keyword arguments corresponding to fields on the
# request, apply these.
# If we have keyword arguments corresponding to fields on the
# request, apply these.

if input is not None:
request.input = input
if voice is not None:
request.voice = voice
if audio_config is not None:
request.audio_config = audio_config
if input is not None:
request.input = input
if voice is not None:
request.voice = voice
if audio_config is not None:
request.audio_config = audio_config

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method.wrap_method(
self._transport.synthesize_speech,
default_timeout=None,
client_info=_client_info,
)
rpc = self._transport._wrapped_methods[self._transport.synthesize_speech]

# Send the request.
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,27 @@

import abc
import typing
import pkg_resources

from google import auth
from google.api_core import exceptions # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google.api_core import retry as retries # type: ignore
from google.auth import credentials # type: ignore

from google.cloud.texttospeech_v1.types import cloud_tts


try:
_client_info = gapic_v1.client_info.ClientInfo(
gapic_version=pkg_resources.get_distribution(
"google-cloud-texttospeech"
).version
)
except pkg_resources.DistributionNotFound:
_client_info = gapic_v1.client_info.ClientInfo()


class TextToSpeechTransport(abc.ABC):
"""Abstract transport class for TextToSpeech."""

Expand All @@ -34,6 +48,9 @@ def __init__(
*,
host: str = "texttospeech.googleapis.com",
credentials: credentials.Credentials = None,
credentials_file: typing.Optional[str] = None,
scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES,
quota_project_id: typing.Optional[str] = None,
**kwargs,
) -> None:
"""Instantiate the transport.
Expand All @@ -45,6 +62,12 @@ def __init__(
credentials identify the application to the service; if none
are specified, the client will attempt to ascertain the
credentials from the environment.
credentials_file (Optional[str]): A file with credentials that can
be loaded with :func:`google.auth.load_credentials_from_file`.
This argument is mutually exclusive with credentials.
scope (Optional[Sequence[str]]): A list of scopes.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
"""
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
if ":" not in host:
Expand All @@ -53,12 +76,38 @@ def __init__(

# If no credentials are provided, then determine the appropriate
# defaults.
if credentials is None:
credentials, _ = auth.default(scopes=self.AUTH_SCOPES)
if credentials and credentials_file:
raise exceptions.DuplicateCredentialArgs(
"'credentials_file' and 'credentials' are mutually exclusive"
)

if credentials_file is not None:
credentials, _ = auth.load_credentials_from_file(
credentials_file, scopes=scopes, quota_project_id=quota_project_id
)

elif credentials is None:
credentials, _ = auth.default(
scopes=scopes, quota_project_id=quota_project_id
)

# Save the credentials.
self._credentials = credentials

# Lifted into its own function so it can be stubbed out during tests.
self._prep_wrapped_messages()

def _prep_wrapped_messages(self):
# Precompute the wrapped methods.
self._wrapped_methods = {
self.list_voices: gapic_v1.method.wrap_method(
self.list_voices, default_timeout=None, client_info=_client_info
),
self.synthesize_speech: gapic_v1.method.wrap_method(
self.synthesize_speech, default_timeout=None, client_info=_client_info
),
}

@property
def list_voices(
self
Expand Down
Loading