我使用了谷歌Text2Speech应用程序接口,它工作得很好,但我想调整一下音高。我用了gTTS。
tts = gTTS("ご返信ありがとうございます。", lang = 'ja')
我该怎么做呢?提前感谢!
发布于 2021-10-01 11:27:10
通过查看official documentation,text2speech应用编程接口有一个AudioConfig
函数,您可以在该函数中传球。音调可以在[-20.0, 20.0]
范围内更改。这是一个很好用的例子。
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"')
https://stackoverflow.com/questions/69405036
复制相似问题