【发布时间】:2018-04-10 05:25:52
【问题描述】:
我尝试使用谷歌云 API 进行文本语音转换,这是示例代码,它适用于英语;但是当我将 language_code='en-US' 更改为 'zh-CN' 并将输入文本设置为中文单词时,显示错误: 400 没有与 TTS 请求匹配的 TTS 语音。请更正语音选择参数,然后重试。
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',
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]
请帮助我使用中文时如何设置参数?
【问题讨论】:
-
来自谷歌云网站,好像还不支持中文语音API。
-
你解决了这个问题吗?我正在用中文尝试谷歌的tts,也遇到了同样的问题。我对javascript不是很有经验。