简体   繁体   English

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

[英]How to adjust Pronunciation Pitch in Google Text to Speech API

I used the Google Text2Speech API, it works well but I'd like to adjust the pitch.我使用了 Google Text2Speech API,它运行良好,但我想调整音调。 I used the gTTS.我用的是 gTTS。

tts = gTTS("ご返信ありがとうございます。", lang = 'ja')

How should I go ahead?我应该怎么提前go? Thanks in advance!提前致谢!

Looking through the official documentation the text2speech API has an AudioConfig function where you can pass in the pitch.查看官方文档,text2speech API 有一个AudioConfig function,您可以在其中传递音高。 The pitch can be changed in the range [-20.0, 20.0] .间距可以在[-20.0, 20.0]范围内更改。 Here is a workinng example.这是一个工作示例。

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"')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Cloud Text To Speech API 强制发音为单词 - Google Cloud Text To Speech API force pronunciation as word 如何使用 Google Cloud Translate 获取英文字母的翻译文本发音? - How to get translated text pronunciation in english letters using Google Cloud Translate? 如何在 Google Text to Speech 中添加暂停? - How to add pause in Google Text to Speech? 如何允许团队成员使用我的 Google Cloud Speech-to-Text API 帐户? - How do I allow a team member to use my Google Cloud Speech-to-Text API account? 使用本机 JavaScript 向 Google Cloud 文本转语音 API 进行身份验证 - Authenticate to Google Cloud text-to-speech API using native JavaScript 谷歌翻译 API 文字转语音:http 请求被禁止 - Google Translate API text-to-speech: http requests forbidden Firebase 具有用于文本到语音的谷歌应用程序凭据的云功能 API - Firebase cloud functions with google application credentials for text to speech API Flutter:Google Speech-To-Text API 总是返回 null - Flutter: Google Speech-To-Text API always returns null 谷歌语音 API Python 无响应 - Google Speech API Python not responding 如何使用服务帐户对谷歌文本到语音进行身份验证 - how to authenticate to google text-to-speech with service account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM