如何使用python呼叫Google TTS Wavenet语音

时间:2019-07-03 15:05:58

标签: python text-to-speech google-cloud-speech

我正在使用the TTS library from Google。我在Python中的代码与their sample code几乎相同。但是我无法在启用WaveNet语音的情况下致电他们的服务(我的目标是非英语,但也显示为WaveNet语音支持)。我的假设是它将基于此param.,但我看不到它在任何地方的用途。

1 个答案:

答案 0 :(得分:1)

弄清楚:

# Build the voice request, select the language code ("en-US") and the ssml
# voice gender ("neutral")
voice = texttospeech.types.VoiceSelectionParams(
    language_code='cs-CZ',
    name="cs-CZ-Wavenet-A",
    ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE)

# Select the type of audio file you want returned
audio_config = texttospeech.types.AudioConfig(
    audio_encoding=texttospeech.enums.AudioEncoding.MP3,
    pitch=0)

# 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)

here上的JSON示例中可以找到 name参数。例如,在捷克语中,它是 cs-CZ-Wavenet-A “ cs-CZ-Standard-A”