簡體   English   中英

如何在 Google Text to Speech 中調整發音音高 API

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

我使用了 Google Text2Speech API,它運行良好,但我想調整音調。 我用的是 gTTS。

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

我應該怎么提前go? 提前致謝!

查看官方文檔,text2speech API 有一個AudioConfig function,您可以在其中傳遞音高。 間距可以在[-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"')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM