GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added Audio Profile sample by happyhuman · Pull Request #1538 · GoogleCloudPlatform/python-docs-samples

Added Audio Profile sample #1538

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.

Sign up for GitHub

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

Merged
happyhuman merged 19 commits into master from audio_profile
Jul 12, 2018

Uh oh!

There was an error while loading. Please reload this page.

Merged

Added Audio Profile sample #1538

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
46d08a7
Added Audio Profile sample
happyhuman Jun 21, 2018
0b5d99e
Adjusted the row lengths
happyhuman Jun 21, 2018
8fe9b3d
Adjusted the row length
happyhuman Jun 21, 2018
a0a2d24
Fixed Import orders
happyhuman Jun 21, 2018
f57d06a
Fixed print statement
happyhuman Jun 21, 2018
2616075
Debugging the unit test
happyhuman Jun 21, 2018
7bc5b37
Fixed the unit test
happyhuman Jun 21, 2018
e2d5a62
Merge branch 'master' into audio_profile
happyhuman Jun 27, 2018
8483244
Some fixes per Noah's suggestions.
happyhuman Jul 2, 2018
19da528
Renamed the function name in the test.
happyhuman Jul 2, 2018
d4d6135
Multilined the long line.
happyhuman Jul 2, 2018
3c068e6
Fixed the misspelling
happyhuman Jul 2, 2018
8dd0ab4
Merge branch 'master' into audio_profile
happyhuman Jul 2, 2018
dc88c50
Fixed the long line
happyhuman Jul 2, 2018
f7adbf4
Forcing the CicleCi to build again
happyhuman Jul 6, 2018
c01d484
Merge branch 'master' into audio_profile
happyhuman Jul 9, 2018
2d3d3d7
Changing Inc to LLC
happyhuman Jul 9, 2018
7b2c8c7
Updated library version.
happyhuman Jul 9, 2018
6c80e2d
Generated README.rst
happyhuman Jul 11, 2018
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

37 changes: 35 additions & 2 deletions 37 texttospeech/cloud-client/README.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Google Cloud Text-to-Speech API Python Samples
: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.
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.
Comment thread

@nnegrey nnegrey Jul 12, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch this one back I think.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions



Expand Down Expand Up @@ -153,6 +153,39 @@ To run this sample:



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
Expand All @@ -170,4 +203,4 @@ to `browse the source`_ and `report issues`_.
https://github.com/GoogleCloudPlatform/google-cloud-python/issues


.. _Google Cloud SDK: https://cloud.google.com/sdk/
.. _Google Cloud SDK: https://cloud.google.com/sdk/
3 changes: 3 additions & 0 deletions 3 texttospeech/cloud-client/README.rst.in
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ samples:
- name: Synthesize file
file: synthesize_file.py
show_help: True
- name: Audio profile
file: audio_profile.py
show_help: True

cloud_client_library: true
70 changes: 70 additions & 0 deletions 70 texttospeech/cloud-client/audio_profile.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/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"
"""

import argparse


# [START tts_synthesize_text_with_audio_profile]
def synthesize_text_with_audio_profile(text, output, effects_profile_id):
"""Synthesizes speech from the input string of text."""
from google.cloud import texttospeech_v1beta1 as 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(
Comment thread

@nnegrey nnegrey Jul 12, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have a comment about what some of the effects_profile_ids are.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
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_with_audio_profile]
Comment thread

@nnegrey nnegrey Jul 12, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could delete the new line.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions


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)
34 changes: 34 additions & 0 deletions 34 texttospeech/cloud-client/audio_profile_test.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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)
Comment thread

@dizcology dizcology Jul 13, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use pytest's temp file for this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
2 changes: 1 addition & 1 deletion 2 texttospeech/cloud-client/requirements.txt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-texttospeech==0.1.0
google-cloud-texttospeech==0.2.0
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.