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

migrate code from googleapis/python-texttospeech #8483

Merged
merged 73 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
2ca0400
Add text-to-speech beta samples [(#1421)](https://github.com/GoogleCl…
nnegrey Mar 26, 2018
768a102
Regenerate the README files and fix the Open in Cloud Shell link for …
Apr 7, 2018
e68eaed
Update READMEs to fix numbering and add git clone [(#1464)](https://g…
frankyn Apr 26, 2018
59640bb
Update library to GA [(#1523)](https://github.com/GoogleCloudPlatform…
nnegrey Jun 14, 2018
79e5908
Rollback Changes [(#1539)](https://github.com/GoogleCloudPlatform/pyt…
nnegrey Jun 22, 2018
1cd3eed
Fixes link render typo [(#1545)](https://github.com/GoogleCloudPlatfo…
alixhami Jun 27, 2018
b04675d
[DO NOT MERGE] Added Audio Profile sample [(#1538)](https://github.co…
happyhuman Jul 12, 2018
9189e66
Diarization Output Modified [(#1586)](https://github.com/GoogleCloudP…
happyhuman Jul 20, 2018
aafcfcc
TTS region tag update [(#1646)](https://github.com/GoogleCloudPlatfor…
alixhami Aug 21, 2018
2868c01
Access Display Names of enum fields via enum object [(#1738)](https:/…
beccasaurus Oct 15, 2018
0aee526
Auto-update dependencies. [(#1980)](https://github.com/GoogleCloudPla…
dpebot Feb 6, 2019
05a82d7
Update beta samples to GA [(#2008)](https://github.com/GoogleCloudPla…
nnegrey Feb 22, 2019
be3a50a
fix: MP3 file test for Text-to-Speech SSML addresses [(#2378)](https:…
crowdus Sep 4, 2019
e332e76
Adds updates for samples profiler ... vision [(#2439)](https://github…
gguuss Oct 7, 2019
4a642ee
Add voice selection by name [(#2687)](https://github.com/GoogleCloudP…
texasmichelle Jan 11, 2020
3ef8ad4
chore(deps): update dependency google-cloud-texttospeech to v1 [(#321…
renovate-bot Mar 29, 2020
a7956f6
Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatf…
kurtisvg Apr 2, 2020
fb03368
chore: some lint fixes [(#3750)](https://github.com/GoogleCloudPlatfo…
May 13, 2020
1d31a0b
fix: move samples into samples/snippets
busunkim96 May 13, 2020
d3f5a11
chore: remove noxfile config
busunkim96 May 19, 2020
f0acca6
feat!: regenerate with microgenerator (#30)
busunkim96 Jun 1, 2020
55ce9c9
samples: update library dep to 2.0.0 (#36)
busunkim96 Jun 2, 2020
04a9a46
chore(deps): update dependency google-cloud-texttospeech to v2.1.0 (#57)
renovate-bot Jun 24, 2020
0dde73a
chore(deps): update dependency google-cloud-texttospeech to v2.2.0 (#78)
renovate-bot Aug 12, 2020
16d79c0
chore(deps): update dependency google-cloud-texttospeech to v2.3.0 (#…
renovate-bot Apr 1, 2021
ef5d19c
chore(deps): update dependency pytest to v6 (#126)
renovate-bot Apr 28, 2021
4106030
chore(deps): update dependency pytest to v6.2.4 (#135)
renovate-bot May 14, 2021
434c952
chore(deps): update dependency google-cloud-texttospeech to v2.4.0 (#…
renovate-bot Jun 1, 2021
249b361
chore(deps): update dependency google-cloud-texttospeech to v2.5.0 (#…
renovate-bot Jul 1, 2021
f6b387d
chore(deps): update dependency google-cloud-texttospeech to v2.5.1 (#…
renovate-bot Jul 22, 2021
af57a51
chore(deps): update dependency google-cloud-texttospeech to v2.5.2 (#…
renovate-bot Jul 29, 2021
b61c0c9
chore(deps): update dependency pytest to v6.2.5 (#182)
renovate-bot Aug 31, 2021
6f99b2b
chore(deps): update dependency google-cloud-texttospeech to v2.5.3 (#…
renovate-bot Sep 27, 2021
95dd725
chore(deps): update dependency google-cloud-texttospeech to v2.6.0 (#…
renovate-bot Oct 7, 2021
0a7feb0
chore(deps): update dependency google-cloud-texttospeech to v2.7.0 (#…
renovate-bot Oct 25, 2021
e81d986
chore(deps): update dependency google-cloud-texttospeech to v2.7.1 (#…
renovate-bot Nov 2, 2021
f378a31
chore(deps): update dependency google-cloud-texttospeech to v2.8.0 (#…
renovate-bot Nov 15, 2021
065bc72
chore(deps): update dependency google-cloud-texttospeech to v2.9.0 (#…
renovate-bot Nov 20, 2021
5915180
docs: Added virtualenv comment for clarity (#225)
nayaknishant Dec 6, 2021
f605faf
chore(deps): update dependency google-cloud-texttospeech to v2.9.1 (#…
renovate-bot Jan 19, 2022
65eb3f0
chore(deps): update all dependencies (#247)
renovate-bot Feb 9, 2022
3d9ec42
chore(deps): update dependency pytest to v7.0.1 (#251)
renovate-bot Feb 26, 2022
4b0f6ca
chore(deps): update all dependencies (#255)
renovate-bot Mar 1, 2022
aa4aa9c
chore(deps): update dependency google-cloud-texttospeech to v2.10.2 (…
renovate-bot Mar 8, 2022
92459ab
chore(deps): update dependency google-cloud-texttospeech to v2.11.0 (…
renovate-bot Mar 12, 2022
37383a0
chore(deps): update dependency pytest to v7.1.0 (#270)
renovate-bot Mar 13, 2022
3fce75e
chore(deps): update dependency pytest to v7.1.1 (#271)
renovate-bot Mar 19, 2022
ee2d6c8
chore(python): add nox session to sort python imports (#285)
gcf-owl-bot[bot] Apr 21, 2022
8c6fd4d
chore(deps): update dependency pytest to v7.1.2 (#288)
renovate-bot Apr 25, 2022
7960370
chore(deps): update all dependencies (#298)
renovate-bot Jul 16, 2022
e16d3de
chore(deps): update all dependencies (#312)
renovate-bot Aug 2, 2022
77d95e3
chore(deps): update dependency google-cloud-texttospeech to v2.12.1 (…
renovate-bot Aug 16, 2022
49ab309
chore(deps): update dependency pytest to v7.1.3 (#328)
renovate-bot Sep 6, 2022
1334891
chore(deps): update dependency google-cloud-texttospeech to v2.12.2 (…
renovate-bot Oct 4, 2022
9ba072f
chore(deps): update dependency google-cloud-texttospeech to v2.12.3 (…
renovate-bot Oct 18, 2022
97a1bf9
chore(deps): update dependency pytest to v7.2.0 (#341)
renovate-bot Oct 26, 2022
0c24763
Merge remote-tracking branch 'migration/main' into python-texttospeec…
msampathkumar Nov 10, 2022
449e5a9
Update CODEOWNERS file and update Copyright for audio_profile.py and …
msampathkumar Nov 10, 2022
31ff224
Update copyright for all .py files in texttospeecch/snippets/
msampathkumar Nov 10, 2022
9980ef8
Merge branch 'main' into python-texttospeech-migration
msampathkumar Nov 11, 2022
b3dc800
Merge branch 'main' into python-texttospeech-migration
msampathkumar Nov 11, 2022
765404d
Merge branch 'main' into python-texttospeech-migration
msampathkumar Nov 14, 2022
9c7e7fc
Update .github/CODEOWNERS
msampathkumar Nov 14, 2022
a4d14bd
Update .github/CODEOWNERS
msampathkumar Nov 14, 2022
16a8501
Update blunderbuss.yml
msampathkumar Nov 14, 2022
6769eda
Update quickstart.py license header
msampathkumar Nov 14, 2022
f2b0c37
Merge branch 'main' into python-texttospeech-migration
msampathkumar Nov 15, 2022
715f176
Add missing copyright headers to text files
msampathkumar Nov 15, 2022
b495479
Merge branch 'main' into python-texttospeech-migration
msampathkumar Nov 15, 2022
6f63190
Update header-checker-lint.yml to exclude hello.txt and example.txt
msampathkumar Nov 15, 2022
f7b415a
Merge branch 'main' into python-texttospeech-migration
msampathkumar Nov 15, 2022
f831b88
chore(header): update to reference specific files
dandhlee Nov 16, 2022
3168389
Merge branch 'main' into python-texttospeech-migration
dandhlee Nov 16, 2022
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
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
/secretmanager/**/* @GoogleCloudPlatform/aap-dpes @GoogleCloudPlatform/python-samples-reviewers
/storage/**/* @GoogleCloudPlatform/cloud-storage-dpes @GoogleCloudPlatform/python-samples-reviewers
/storagetransfer/**/* @GoogleCloudPlatform/cloud-storage-dpes @GoogleCloudPlatform/python-samples-reviewers
/texttospeech/snippets @GoogleCloudPlatform/dee-platform-ops @GoogleCloudPlatform/python-samples-reviewers
msampathkumar marked this conversation as resolved.
Show resolved Hide resolved
/trace/**/* @ymotongpoo @GoogleCloudPlatform/python-samples-reviewers
/translate/**/* @nicain @GoogleCloudPlatform/python-samples-reviewers
/workflows/**/* @GoogleCloudPlatform/python-samples-reviewers
/workflows/**/* @GoogleCloudPlatform/python-samples-reviewers
msampathkumar marked this conversation as resolved.
Show resolved Hide resolved
234 changes: 234 additions & 0 deletions texttospeech/snippets/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@

.. This file is automatically generated. Do not edit this file directly.

Google Cloud Text-to-Speech API Python Samples
===============================================================================

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/README.rst


This directory contains samples for Google Cloud Text-to-Speech API. The `Google Cloud Text To Speech API`_ enables you to generate and customize synthesized speech from text or SSML.




.. _Google Cloud Text-to-Speech API: https://cloud.google.com/text-to-speech/docs/


Setup
-------------------------------------------------------------------------------



Authentication
++++++++++++++

This sample requires you to have authentication setup. Refer to the
`Authentication Getting Started Guide`_ for instructions on setting up
credentials for applications.

.. _Authentication Getting Started Guide:
https://cloud.google.com/docs/authentication/getting-started




Install Dependencies
++++++++++++++++++++

#. Clone python-docs-samples and change directory to the sample directory you want to use.

.. code-block:: bash

$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git

#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions.

.. _Python Development Environment Setup Guide:
https://cloud.google.com/python/setup

#. Create a virtualenv. Samples are compatible with Python 3.6+.

.. code-block:: bash

$ virtualenv env
$ source env/bin/activate

#. Install the dependencies needed to run the samples.

.. code-block:: bash

$ pip install -r requirements.txt

.. _pip: https://pip.pypa.io/
.. _virtualenv: https://virtualenv.pypa.io/






Samples
-------------------------------------------------------------------------------


Quickstart
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/quickstart.py,/README.rst




To run this sample:

.. code-block:: bash

$ python quickstart.py




List voices
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/list_voices.py,/README.rst




To run this sample:

.. code-block:: bash

$ python list_voices.py




Synthesize text
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/synthesize_text.py,/README.rst




To run this sample:

.. code-block:: bash

$ python synthesize_text.py


usage: synthesize_text.py [-h] (--text TEXT | --ssml SSML)

Google Cloud Text-To-Speech API sample application .

Example usage:
python synthesize_text.py --text "hello"
python synthesize_text.py --ssml "<speak>Hello there.</speak>"

optional arguments:
-h, --help show this help message and exit
--text TEXT The text from which to synthesize speech.
--ssml SSML The ssml string from which to synthesize speech.





Synthesize file
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/synthesize_file.py,/README.rst




To run this sample:

.. code-block:: bash

$ python synthesize_file.py


usage: synthesize_file.py [-h] (--text TEXT | --ssml SSML)

Google Cloud Text-To-Speech API sample application .

Example usage:
python synthesize_file.py --text resources/hello.txt
python synthesize_file.py --ssml resources/hello.ssml

optional arguments:
-h, --help show this help message and exit
--text TEXT The text file from which to synthesize speech.
--ssml SSML The ssml file from which to synthesize speech.





Audio profile
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=/audio_profile.py,/README.rst




To run this sample:

.. code-block:: bash

$ python audio_profile.py


usage: audio_profile.py [-h] [--output OUTPUT] [--text TEXT]
[--effects_profile_id EFFECTS_PROFILE_ID]

Google Cloud Text-To-Speech API sample application for audio profile.

Example usage:
python audio_profile.py --text "hello" --effects_profile_id
"telephony-class-application" --output "output.mp3"

optional arguments:
-h, --help show this help message and exit
--output OUTPUT The output mp3 file.
--text TEXT The text from which to synthesize speech.
--effects_profile_id EFFECTS_PROFILE_ID
The audio effects profile id to be applied.









The client library
-------------------------------------------------------------------------------

This sample uses the `Google Cloud Client Library for Python`_.
You can read the documentation for more details on API usage and use GitHub
to `browse the source`_ and `report issues`_.

.. _Google Cloud Client Library for Python:
https://googlecloudplatform.github.io/google-cloud-python/
.. _browse the source:
https://github.com/GoogleCloudPlatform/google-cloud-python
.. _report issues:
https://github.com/GoogleCloudPlatform/google-cloud-python/issues



.. _Google Cloud SDK: https://cloud.google.com/sdk/
29 changes: 29 additions & 0 deletions texttospeech/snippets/README.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file is used to generate README.rst

product:
name: Google Cloud Text-to-Speech API
short_name: Cloud TTS API
url: https://cloud.google.com/text-to-speech/docs/
description: >
The `Google Cloud Text To Speech API`_ enables you to generate and customize synthesized speech from text or SSML.

setup:
- auth
- install_deps

samples:
- name: Quickstart
file: quickstart.py
- name: List voices
file: list_voices.py
- name: Synthesize text
file: synthesize_text.py
show_help: True
- name: Synthesize file
file: synthesize_file.py
show_help: True
- name: Audio profile
file: audio_profile.py
show_help: True

cloud_client_library: true
75 changes: 75 additions & 0 deletions texttospeech/snippets/audio_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# All Rights Reserved.

"""Google Cloud Text-To-Speech API sample application for audio profile.

Example usage:
python audio_profile.py --text "hello" --effects_profile_id
"telephony-class-application" --output "output.mp3"
"""

import argparse


# [START tts_synthesize_text_audio_profile]
# [START tts_synthesize_text_audio_profile_beta]
def synthesize_text_with_audio_profile(text, output, effects_profile_id):
"""Synthesizes speech from the input string of text."""
from google.cloud import texttospeech

client = texttospeech.TextToSpeechClient()

input_text = texttospeech.SynthesisInput(text=text)

# Note: the voice can also be specified by name.
# Names of voices can be retrieved with client.list_voices().
voice = texttospeech.VoiceSelectionParams(language_code="en-US")

# Note: you can pass in multiple effects_profile_id. They will be applied
# in the same order they are provided.
audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.MP3,
effects_profile_id=[effects_profile_id],
)

response = client.synthesize_speech(
input=input_text, voice=voice, audio_config=audio_config
)

# The response's audio_content is binary.
with open(output, "wb") as out:
out.write(response.audio_content)
print('Audio content written to file "%s"' % output)


# [END tts_synthesize_text_audio_profile_beta]
# [END tts_synthesize_text_audio_profile]


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument("--output", help="The output mp3 file.")
parser.add_argument("--text", help="The text from which to synthesize speech.")
parser.add_argument(
"--effects_profile_id", help="The audio effects profile id to be applied."
)

args = parser.parse_args()

synthesize_text_with_audio_profile(args.text, args.output, args.effects_profile_id)
35 changes: 35 additions & 0 deletions texttospeech/snippets/audio_profile_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import os.path

import audio_profile

TEXT = "hello"
OUTPUT = "output.mp3"
EFFECTS_PROFILE_ID = "telephony-class-application"


def test_audio_profile(capsys):
if os.path.exists(OUTPUT):
os.remove(OUTPUT)
assert not os.path.exists(OUTPUT)
audio_profile.synthesize_text_with_audio_profile(TEXT, OUTPUT, EFFECTS_PROFILE_ID)
out, err = capsys.readouterr()

assert ('Audio content written to file "%s"' % OUTPUT) in out
assert os.path.exists(OUTPUT)
os.remove(OUTPUT)
Loading