首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Google Text to Speech API中调整发音音调

如何在Google Text to Speech API中调整发音音调
EN

Stack Overflow用户
提问于 2021-10-01 11:20:08
回答 1查看 61关注 0票数 0

我使用了谷歌Text2Speech应用程序接口,它工作得很好,但我想调整一下音高。我用了gTTS。

代码语言:javascript
运行
复制
tts = gTTS("ご返信ありがとうございます。", lang = 'ja')

我该怎么做呢?提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-01 11:27:10

通过查看official documentation,text2speech应用编程接口有一个AudioConfig函数,您可以在该函数中传球。音调可以在[-20.0, 20.0]范围内更改。这是一个很好用的例子。

代码语言:javascript
运行
复制
from google.cloud import texttospeech

# Instantiates a client
client = texttospeech.TextToSpeechClient()

# Set the text input to be synthesized
synthesis_input = texttospeech.SynthesisInput(text="Hello, World!")

# Build the voice request, select the language code ("en-US") and the ssml
# voice gender ("neutral")
voice = texttospeech.VoiceSelectionParams(
    language_code="en-US", ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL
)

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

# Perform the text-to-speech request on the text input with the selected
# voice parameters and audio file type
response = client.synthesize_speech(
    input=synthesis_input, voice=voice, audio_config=audio_config
)

# The response's audio_content is binary.
with open("output.mp3", "wb") as out:
    # Write the response to the output file.
    out.write(response.audio_content)
    print('Audio content written to file "output.mp3"')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69405036

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档