diff --git a/texttospeech/cloud-client/README.rst b/texttospeech/cloud-client/README.rst index 7b877be1328b..6d48ed92331c 100644 --- a/texttospeech/cloud-client/README.rst +++ b/texttospeech/cloud-client/README.rst @@ -1,206 +1,3 @@ -.. This file is automatically generated. Do not edit this file directly. +These samples have been moved. -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 2.7 and 3.4+. - - .. 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 "Hello there." - - 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" - - 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/ \ No newline at end of file +https://github.com/googleapis/python-texttospeech/tree/master/samples \ No newline at end of file diff --git a/texttospeech/cloud-client/README.rst.in b/texttospeech/cloud-client/README.rst.in deleted file mode 100644 index 8be6ab467741..000000000000 --- a/texttospeech/cloud-client/README.rst.in +++ /dev/null @@ -1,29 +0,0 @@ -# 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 diff --git a/texttospeech/cloud-client/audio_profile.py b/texttospeech/cloud-client/audio_profile.py deleted file mode 100644 index 01f2ba884ba3..000000000000 --- a/texttospeech/cloud-client/audio_profile.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 Google LLC. All Rights Reserved. -# -# 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. - -"""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.types.SynthesisInput(text=text) - - # Note: the voice can also be specified by name. - # Names of voices can be retrieved with client.list_voices(). - voice = texttospeech.types.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.types.AudioConfig( - audio_encoding=texttospeech.enums.AudioEncoding.MP3, - effects_profile_id=[effects_profile_id]) - - response = client.synthesize_speech(input_text, voice, 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) diff --git a/texttospeech/cloud-client/audio_profile_test.py b/texttospeech/cloud-client/audio_profile_test.py deleted file mode 100644 index 43a30bf06d16..000000000000 --- a/texttospeech/cloud-client/audio_profile_test.py +++ /dev/null @@ -1,34 +0,0 @@ -# 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) diff --git a/texttospeech/cloud-client/list_voices.py b/texttospeech/cloud-client/list_voices.py deleted file mode 100644 index a2da5a178528..000000000000 --- a/texttospeech/cloud-client/list_voices.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 Google Inc. All Rights Reserved. -# -# 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. - -"""Google Cloud Text-To-Speech API sample application. - -Example usage: - python list_voices.py -""" - - -# [START tts_list_voices] -def list_voices(): - """Lists the available voices.""" - from google.cloud import texttospeech - from google.cloud.texttospeech import enums - client = texttospeech.TextToSpeechClient() - - # Performs the list voices request - voices = client.list_voices() - - for voice in voices.voices: - # Display the voice's name. Example: tpc-vocoded - print('Name: {}'.format(voice.name)) - - # Display the supported language codes for this voice. Example: "en-US" - for language_code in voice.language_codes: - print('Supported language: {}'.format(language_code)) - - ssml_gender = enums.SsmlVoiceGender(voice.ssml_gender) - - # Display the SSML Voice Gender - print('SSML Voice Gender: {}'.format(ssml_gender.name)) - - # Display the natural sample rate hertz for this voice. Example: 24000 - print('Natural Sample Rate Hertz: {}\n'.format( - voice.natural_sample_rate_hertz)) -# [END tts_list_voices] - - -if __name__ == '__main__': - list_voices() diff --git a/texttospeech/cloud-client/list_voices_test.py b/texttospeech/cloud-client/list_voices_test.py deleted file mode 100644 index fd3255694922..000000000000 --- a/texttospeech/cloud-client/list_voices_test.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2018, Google, Inc. -# 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 list_voices - - -def test_list_voices(capsys): - list_voices.list_voices() - out, err = capsys.readouterr() - - assert 'en-US' in out - assert 'SSML Voice Gender: MALE' in out - assert 'SSML Voice Gender: FEMALE' in out diff --git a/texttospeech/cloud-client/quickstart.py b/texttospeech/cloud-client/quickstart.py deleted file mode 100644 index f462139d794b..000000000000 --- a/texttospeech/cloud-client/quickstart.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 Google Inc. All Rights Reserved. -# -# 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. - -"""Google Cloud Text-To-Speech API sample application . - -Example usage: - python quickstart.py -""" - - -def run_quickstart(): - # [START tts_quickstart] - """Synthesizes speech from the input string of text or ssml. - - Note: ssml must be well-formed according to: - https://www.w3.org/TR/speech-synthesis/ - """ - from google.cloud import texttospeech - - # Instantiates a client - client = texttospeech.TextToSpeechClient() - - # Set the text input to be synthesized - synthesis_input = texttospeech.types.SynthesisInput(text="Hello, World!") - - # Build the voice request, select the language code ("en-US") and the ssml - # voice gender ("neutral") - voice = texttospeech.types.VoiceSelectionParams( - language_code='en-US', - ssml_gender=texttospeech.enums.SsmlVoiceGender.NEUTRAL) - - # Select the type of audio file you want returned - audio_config = texttospeech.types.AudioConfig( - audio_encoding=texttospeech.enums.AudioEncoding.MP3) - - # Perform the text-to-speech request on the text input with the selected - # voice parameters and audio file type - response = client.synthesize_speech(synthesis_input, voice, audio_config) - - # The response's audio_content is binary. - with open('output.mp3', 'wb') as out: - # Write the response to the output file. - out.write(response.audio_content) - print('Audio content written to file "output.mp3"') - # [END tts_quickstart] - - -if __name__ == '__main__': - run_quickstart() diff --git a/texttospeech/cloud-client/requirements-test.txt b/texttospeech/cloud-client/requirements-test.txt deleted file mode 100644 index 781d4326c947..000000000000 --- a/texttospeech/cloud-client/requirements-test.txt +++ /dev/null @@ -1 +0,0 @@ -pytest==5.3.2 diff --git a/texttospeech/cloud-client/requirements.txt b/texttospeech/cloud-client/requirements.txt deleted file mode 100644 index 3d00a8bd1f4d..000000000000 --- a/texttospeech/cloud-client/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -future==0.18.2 -google-cloud-texttospeech==1.0.1 diff --git a/texttospeech/cloud-client/resources/example.ssml b/texttospeech/cloud-client/resources/example.ssml deleted file mode 100644 index 1e20716f0dac..000000000000 --- a/texttospeech/cloud-client/resources/example.ssml +++ /dev/null @@ -1,4 +0,0 @@ -123 Street Ln, Small Town, IL 12345 USA -1 Jenny St & Number St, Tutone City, CA 86753 -1 Piazza del Fibonacci, 12358 Pisa, Italy - \ No newline at end of file diff --git a/texttospeech/cloud-client/resources/example.txt b/texttospeech/cloud-client/resources/example.txt deleted file mode 100644 index 9cd7d74db361..000000000000 --- a/texttospeech/cloud-client/resources/example.txt +++ /dev/null @@ -1,3 +0,0 @@ -123 Street Ln, Small Town, IL 12345 USA -1 Jenny St & Number St, Tutone City, CA 86753 -1 Piazza del Fibonacci, 12358 Pisa, Italy diff --git a/texttospeech/cloud-client/resources/hello.ssml b/texttospeech/cloud-client/resources/hello.ssml deleted file mode 100644 index cd347b71fe58..000000000000 --- a/texttospeech/cloud-client/resources/hello.ssml +++ /dev/null @@ -1 +0,0 @@ -Hello there. \ No newline at end of file diff --git a/texttospeech/cloud-client/resources/hello.txt b/texttospeech/cloud-client/resources/hello.txt deleted file mode 100644 index cd773cd131fc..000000000000 --- a/texttospeech/cloud-client/resources/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello there! \ No newline at end of file diff --git a/texttospeech/cloud-client/ssml_addresses.py b/texttospeech/cloud-client/ssml_addresses.py deleted file mode 100644 index dd9276058a44..000000000000 --- a/texttospeech/cloud-client/ssml_addresses.py +++ /dev/null @@ -1,113 +0,0 @@ -# Copyright 2019 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. - - -# [START tts_ssml_address_imports] -import html - -from google.cloud import texttospeech - -# [END tts_ssml_address_imports] - - -# [START tts_ssml_address_audio] -def ssml_to_audio(ssml_text, outfile): - # Generates SSML text from plaintext. - # - # Given a string of SSML text and an output file name, this function - # calls the Text-to-Speech API. The API returns a synthetic audio - # version of the text, formatted according to the SSML commands. This - # function saves the synthetic audio to the designated output file. - # - # Args: - # ssml_text: string of SSML text - # outfile: string name of file under which to save audio output - # - # Returns: - # nothing - - # Instantiates a client - client = texttospeech.TextToSpeechClient() - - # Sets the text input to be synthesized - synthesis_input = texttospeech.types.SynthesisInput(ssml=ssml_text) - - # Builds the voice request, selects the language code ("en-US") and - # the SSML voice gender ("MALE") - voice = texttospeech.types.VoiceSelectionParams( - language_code='en-US', - ssml_gender=texttospeech.enums.SsmlVoiceGender.MALE) - - # Selects the type of audio file to return - audio_config = texttospeech.types.AudioConfig( - audio_encoding=texttospeech.enums.AudioEncoding.MP3) - - # Performs the text-to-speech request on the text input with the selected - # voice parameters and audio file type - response = client.synthesize_speech(synthesis_input, voice, audio_config) - - # Writes the synthetic audio to the output file. - with open(outfile, 'wb') as out: - out.write(response.audio_content) - print('Audio content written to file ' + outfile) - # [END tts_ssml_address_audio] - - -# [START tts_ssml_address_ssml] -def text_to_ssml(inputfile): - # Generates SSML text from plaintext. - # Given an input filename, this function converts the contents of the text - # file into a string of formatted SSML text. This function formats the SSML - # string so that, when synthesized, the synthetic audio will pause for two - # seconds between each line of the text file. This function also handles - # special text characters which might interfere with SSML commands. - # - # Args: - # inputfile: string name of plaintext file - # - # Returns: - # A string of SSML text based on plaintext input - - # Parses lines of input file - with open(inputfile, 'r') as f: - raw_lines = f.read() - - # Replace special characters with HTML Ampersand Character Codes - # These Codes prevent the API from confusing text with - # SSML commands - # For example, '<' --> '<' and '&' --> '&' - - escaped_lines = html.escape(raw_lines) - - # Convert plaintext to SSML - # Wait two seconds between each address - ssml = '{}'.format( - escaped_lines.replace('\n', '\n')) - - # Return the concatenated string of ssml script - return ssml -# [END tts_ssml_address_ssml] - - -# [START tts_ssml_address_test] -def main(): - # test example address file - plaintext = 'resources/example.txt' - ssml_text = text_to_ssml(plaintext) - ssml_to_audio(ssml_text, 'resources/example.mp3') - # [END tts_ssml_address_test] - - -if __name__ == '__main__': - main() diff --git a/texttospeech/cloud-client/ssml_addresses_test.py b/texttospeech/cloud-client/ssml_addresses_test.py deleted file mode 100644 index 5f0016085b15..000000000000 --- a/texttospeech/cloud-client/ssml_addresses_test.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2019 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 - -from ssml_addresses import ssml_to_audio -from ssml_addresses import text_to_ssml - - -def test_text_to_ssml(capsys): - - # Read expected SSML output from resources - with open('resources/example.ssml', 'r') as f: - expected_ssml = f.read() - - # Assert plaintext converted to SSML - input_text = 'resources/example.txt' - tested_ssml = text_to_ssml(input_text) - assert expected_ssml == tested_ssml - - -def test_ssml_to_audio(capsys): - - # Read SSML input from resources - with open('resources/example.ssml', 'r') as f: - input_ssml = f.read() - - # Assert audio file generated - ssml_to_audio(input_ssml, 'test_example.mp3') - out, err = capsys.readouterr() - - # Assert MP3 file created - assert os.path.isfile('test_example.mp3') - assert "Audio content written to file test_example.mp3" in out - - # Delete MP3 test file - os.remove("test_example.mp3") diff --git a/texttospeech/cloud-client/synthesize_file.py b/texttospeech/cloud-client/synthesize_file.py deleted file mode 100644 index f62d6330d7d5..000000000000 --- a/texttospeech/cloud-client/synthesize_file.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 Google Inc. All Rights Reserved. -# -# 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. - -"""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 -""" - -import argparse - - -# [START tts_synthesize_text_file] -def synthesize_text_file(text_file): - """Synthesizes speech from the input file of text.""" - from google.cloud import texttospeech - client = texttospeech.TextToSpeechClient() - - with open(text_file, 'r') as f: - text = f.read() - input_text = texttospeech.types.SynthesisInput(text=text) - - # Note: the voice can also be specified by name. - # Names of voices can be retrieved with client.list_voices(). - voice = texttospeech.types.VoiceSelectionParams( - language_code='en-US', - ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE) - - audio_config = texttospeech.types.AudioConfig( - audio_encoding=texttospeech.enums.AudioEncoding.MP3) - - response = client.synthesize_speech(input_text, voice, audio_config) - - # The response's audio_content is binary. - with open('output.mp3', 'wb') as out: - out.write(response.audio_content) - print('Audio content written to file "output.mp3"') -# [END tts_synthesize_text_file] - - -# [START tts_synthesize_ssml_file] -def synthesize_ssml_file(ssml_file): - """Synthesizes speech from the input file of ssml. - - Note: ssml must be well-formed according to: - https://www.w3.org/TR/speech-synthesis/ - """ - from google.cloud import texttospeech - client = texttospeech.TextToSpeechClient() - - with open(ssml_file, 'r') as f: - ssml = f.read() - input_text = texttospeech.types.SynthesisInput(ssml=ssml) - - # Note: the voice can also be specified by name. - # Names of voices can be retrieved with client.list_voices(). - voice = texttospeech.types.VoiceSelectionParams( - language_code='en-US', - ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE) - - audio_config = texttospeech.types.AudioConfig( - audio_encoding=texttospeech.enums.AudioEncoding.MP3) - - response = client.synthesize_speech(input_text, voice, audio_config) - - # The response's audio_content is binary. - with open('output.mp3', 'wb') as out: - out.write(response.audio_content) - print('Audio content written to file "output.mp3"') -# [END tts_synthesize_ssml_file] - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) - group = parser.add_mutually_exclusive_group(required=True) - group.add_argument('--text', - help='The text file from which to synthesize speech.') - group.add_argument('--ssml', - help='The ssml file from which to synthesize speech.') - - args = parser.parse_args() - - if args.text: - synthesize_text_file(args.text) - else: - synthesize_ssml_file(args.ssml) diff --git a/texttospeech/cloud-client/synthesize_file_test.py b/texttospeech/cloud-client/synthesize_file_test.py deleted file mode 100644 index 2652009f98b6..000000000000 --- a/texttospeech/cloud-client/synthesize_file_test.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2018, Google, Inc. -# 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 synthesize_file - -TEXT_FILE = 'resources/hello.txt' -SSML_FILE = 'resources/hello.ssml' - - -def test_synthesize_text_file(capsys): - synthesize_file.synthesize_text_file(text_file=TEXT_FILE) - out, err = capsys.readouterr() - - assert 'Audio content written to file' in out - statinfo = os.stat('output.mp3') - assert statinfo.st_size > 0 - - -def test_synthesize_ssml_file(capsys): - synthesize_file.synthesize_ssml_file(ssml_file=SSML_FILE) - out, err = capsys.readouterr() - - assert 'Audio content written to file' in out - statinfo = os.stat('output.mp3') - assert statinfo.st_size > 0 diff --git a/texttospeech/cloud-client/synthesize_text.py b/texttospeech/cloud-client/synthesize_text.py deleted file mode 100644 index 768c0da03178..000000000000 --- a/texttospeech/cloud-client/synthesize_text.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 Google Inc. All Rights Reserved. -# -# 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. - -"""Google Cloud Text-To-Speech API sample application . - -Example usage: - python synthesize_text.py --text "hello" - python synthesize_text.py --ssml "Hello there." -""" - -import argparse - - -# [START tts_synthesize_text] -def synthesize_text(text): - """Synthesizes speech from the input string of text.""" - from google.cloud import texttospeech - client = texttospeech.TextToSpeechClient() - - input_text = texttospeech.types.SynthesisInput(text=text) - - # Note: the voice can also be specified by name. - # Names of voices can be retrieved with client.list_voices(). - voice = texttospeech.types.VoiceSelectionParams( - language_code='en-US', - name='en-US-Standard-C', - ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE) - - audio_config = texttospeech.types.AudioConfig( - audio_encoding=texttospeech.enums.AudioEncoding.MP3) - - response = client.synthesize_speech(input_text, voice, audio_config) - - # The response's audio_content is binary. - with open('output.mp3', 'wb') as out: - out.write(response.audio_content) - print('Audio content written to file "output.mp3"') -# [END tts_synthesize_text] - - -# [START tts_synthesize_ssml] -def synthesize_ssml(ssml): - """Synthesizes speech from the input string of ssml. - - Note: ssml must be well-formed according to: - https://www.w3.org/TR/speech-synthesis/ - - Example: Hello there. - """ - from google.cloud import texttospeech - client = texttospeech.TextToSpeechClient() - - input_text = texttospeech.types.SynthesisInput(ssml=ssml) - - # Note: the voice can also be specified by name. - # Names of voices can be retrieved with client.list_voices(). - voice = texttospeech.types.VoiceSelectionParams( - language_code='en-US', - name='en-US-Standard-C', - ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE) - - audio_config = texttospeech.types.AudioConfig( - audio_encoding=texttospeech.enums.AudioEncoding.MP3) - - response = client.synthesize_speech(input_text, voice, audio_config) - - # The response's audio_content is binary. - with open('output.mp3', 'wb') as out: - out.write(response.audio_content) - print('Audio content written to file "output.mp3"') -# [END tts_synthesize_ssml] - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) - group = parser.add_mutually_exclusive_group(required=True) - group.add_argument('--text', - help='The text from which to synthesize speech.') - group.add_argument('--ssml', - help='The ssml string from which to synthesize speech.') - - args = parser.parse_args() - - if args.text: - synthesize_text(args.text) - else: - synthesize_ssml(args.ssml) diff --git a/texttospeech/cloud-client/synthesize_text_test.py b/texttospeech/cloud-client/synthesize_text_test.py deleted file mode 100644 index 948d58da26df..000000000000 --- a/texttospeech/cloud-client/synthesize_text_test.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2018, Google, Inc. -# 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 synthesize_text - -TEXT = 'Hello there.' -SSML = 'Hello there.' - - -def test_synthesize_text(capsys): - synthesize_text.synthesize_text(text=TEXT) - out, err = capsys.readouterr() - - assert 'Audio content written to file' in out - statinfo = os.stat('output.mp3') - assert statinfo.st_size > 0 - - -def test_synthesize_ssml(capsys): - synthesize_text.synthesize_ssml(ssml=SSML) - out, err = capsys.readouterr() - - assert 'Audio content written to file' in out - statinfo = os.stat('output.mp3') - assert statinfo.st_size > 0