-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Added Audio Profile sample #1538
Changes from 7 commits
46d08a7
0b5d99e
8fe9b3d
a0a2d24
f57d06a
2616075
7bc5b37
e2d5a62
8483244
19da528
d4d6135
3c068e6
8dd0ab4
dc88c50
f7adbf4
c01d484
2d3d3d7
7b2c8c7
6c80e2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/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 for audio profile. | ||
|
||
Example usage: | ||
python audio_profile.py --text "hello" --effects_profile_id | ||
"telephony-class-application" | ||
""" | ||
|
||
import argparse | ||
|
||
from google.cloud import texttospeech_v1beta1 as texttospeech | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be moved to right between line 31/32. (Just learned this myself) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
|
||
# [START tts_synthesize_text] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update region tag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
def synthesize_text(text, output, effects_profile_id): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. def synthesize_text_with_audio_profile? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
"""Synthesizes speech from the input string of text.""" | ||
client = texttospeech.TextToSpeechClient() | ||
|
||
input_text = texttospeech.types.SynthesisInput(text=text) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this also support ssml? @dizcology Should there be a 2nd snippet for ssml support? |
||
|
||
# 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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
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] | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser( | ||
description=__doc__, | ||
formatter_class=argparse.RawDescriptionHelpFormatter) | ||
parser.add_argument('--text', | ||
help='The text from which to synthesize speech.') | ||
parser.add_argument('--output', | ||
help='The output mp3 file.') | ||
parser.add_argument('--effects_profile_id', | ||
help='The audio effects profile id to be applied.') | ||
|
||
args = parser.parse_args() | ||
|
||
synthesize_text(args.text, args.output, args.effects_profile_id) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2018, Google, Inc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Google LLC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
# 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' | ||
OUTOUT = 'output.mp3' | ||
EFFECTS_PROFILE_ID = 'telephony-class-application' | ||
|
||
|
||
def test_audio_profile(capsys): | ||
if os.path.exists(OUTOUT): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably do the clean-up after it runs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
os.remove(OUTOUT) | ||
assert not os.path.exists(OUTOUT) | ||
audio_profile.synthesize_text(TEXT, OUTOUT, EFFECTS_PROFILE_ID) | ||
out, err = capsys.readouterr() | ||
|
||
assert ('Audio content written to file "%s"' % OUTOUT) in out | ||
assert os.path.exists(OUTOUT) |
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.
Google LLC
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.
Good point, but it is also Google Inc in every other file.
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.
For new files, I've been told we make the effort to update them, but on older files we just leave them.
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.
Done