我是编码的初学者。 我在一个正在使用的小程序上使用Google Cloud Text to Speech API for Python。该功能正在运行,我得到了合成的语音结果,但是MP3文件与我需要的文件不同。我选择了“ en-GB-Wavenet-C”(英国口音的女性声音)作为language_code,但MP3文件听起来像美国口音的男性声音。
我访问了Cloud Text to Speech API网站(https://cloud.google.com/text-to-speech/),并尝试了“ Speak it”演示。我尝试了“ en-GB-Wavenet-C”,听起来像是英国人的女性嗓音。
我想知道合适的代码,以便获得'en-GB-Wavenet-C'语音结果。
我从Windows Subsystem for Linux使用Debian 9.3。
我使用Google Cloud SDK 210.0.0。
谢谢。
此致, 卡祖
这是我的代码:
#!/usr/bin/env python
from google.cloud import texttospeech
client = texttospeech.TextToSpeechClient()
with open('resources/hello.ssml', '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-GB-Wavenet-C')
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]
答案 0 :(得分:1)
voice = texttospeech.types.VoiceSelectionParams(language_code='en-GB-Wavenet-C')
应该是
voice = texttospeech.types.VoiceSelectionParams(language_code='en-GB', name="en-GB-Wavenet-C")