【发布时间】:2021-11-05 08:15:53
【问题描述】:
我正在尝试让 Google TTS 朗读一小段单词并在每个单词之间暂停。我发送到 Google Cloud 的 SSML 示例:
<speak>chaume<break time="3s"/> cuivré, relatif au cuivre</speak>
第一个单词被读出,然后声音停顿三秒钟,但后面的所有内容都被放下了。我已经成功让 TTS 使用相同的代码读取包含中断的较长句子,例如这个:
<speak>Se pure vagolavano allora per una Parma stupenda, prima dello <break time="3s"/>scempio della Bassa dei Magnani orrendamente ricostruita.</speak>
两个样本之间没有任何差异,第一个样本出了什么问题?
我的合成功能稍微定制的版本如下:
def synthesize_text(ssml_text,file_name,tts_lang,tts_voice_name):
"""Synthesizes speech from the input string of text."""
client = texttospeech.TextToSpeechClient(credentials=credentials)
input_text = texttospeech.SynthesisInput(ssml=ssml_text)
# Note: the voice can also be specified by name.
# Names of voices can be retrieved with client.list_voices().
voice = texttospeech.VoiceSelectionParams(
language_code=tts_lang,
name=tts_voice_name,
ssml_gender=texttospeech.SsmlVoiceGender.FEMALE,
)
audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.MP3
)
response = client.synthesize_speech(
request={"input": input_text, "voice": voice, "audio_config": audio_config}
)
# The response's audio_content is binary.
with open(f"{home}/Documents/{file_name}.mp3", "wb") as out:
out.write(response.audio_content)
【问题讨论】:
标签: google-cloud-platform text-to-speech