python-3.x - Google 文字转语音 API 音高调整
问题描述
如何在此代码中将音高调整为 -1.20:
from google.cloud import texttospeech
def text_to_wav(voice_name, text):
language_code = "-".join(voice_name.split("-")[:2])
text_input = texttospeech.SynthesisInput(text=text)
voice_params = texttospeech.VoiceSelectionParams(
language_code=language_code, name=voice_name)
audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.LINEAR16)
client = texttospeech.TextToSpeechClient()
response = client.synthesize_speech(
input=text_input, voice=voice_params, audio_config=audio_config)
filename = f"{language_code}.wav"
with open(filename, "wb") as out:
out.write(response.audio_content)
print(f'Audio content written to "{filename}"')
Google Text-to-Speech 文档对此并不十分清楚。根据文档,可以在 [-20.0, 20.0] 范围内调整“音高”,但是可以在哪里调整此参数。
解决方案
audio_config = texttospeech.AudioConfig(pitch=-1.20, audio_encoding=texttospeech.AudioEncoding.LINEAR16)
推荐阅读
- react-native - 在异步存储中检索保存的用户数据时出错 - React-native
- python - 发布页面后我的插件添加功能丢失
- javascript - 无法在 reactJs 中设置 useState 值
- laravel - Laravel 唯一验证,仅当值不同且没有 id 时
- java - 如何使用流将嵌套对象列表转换为具有相似信息的对象列表
- arduino - 为什么编译到 Wemos D1 mini pro 会出错
- python - 在设计器中取消链接两个模块 - 如何删除箭头?
- windows-subsystem-for-linux - wsl2 配置被忽略
- python - 如何用 plotly 绘制金字塔人口图?
- javascript - lowdb 从 db 文件中删除键值对