-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8483 from GoogleCloudPlatform/python-texttospeech…
…-migration migrate code from googleapis/python-texttospeech
- Loading branch information
Showing
22 changed files
with
1,029 additions
and
2 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.