POST /appletApi/tts/textToVoice
参数名称 | 类型 | 必填 | 描述 |
---|---|---|---|
text | String | 是 | 要转换的文本内容,中文最大支持150个汉字,英文最大支持500个字母 |
speed | Float | 否 | 语速,范围:[-2,6],默认为0。-2代表0.6倍,-1代表0.8倍,0代表1.0倍,1代表1.2倍,2代表1.5倍,6代表2.5倍 |
voiceType | Integer | 否 | 音色ID,默认为0。不同音色价格有差异,完整音色列表请参见腾讯云官方文档 |
volume | Float | 否 | 音量大小,范围[-10,10],默认为0,代表正常音量 |
codec | String | 否 | 返回音频格式,可取值:wav(默认),mp3,pcm |
成功时返回二进制音频数据,Content-Type根据codec参数设置:
// 前端调用示例
fetch('/appletApi/tts/textToVoice', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'text=你好,欢迎使用语音合成服务'
})
.then(response => response.blob())
.then(blob => {
const audio = new Audio(URL.createObjectURL(blob));
audio.play();
});
// 设置语速和音色
fetch('/appletApi/tts/textToVoice', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'text=Hello World&speed=1.2&voiceType=1&volume=2&codec=mp3'
})
.then(response => response.blob())
.then(blob => {
const audio = new Audio(URL.createObjectURL(blob));
audio.play();
});
在 application.yml
中配置腾讯云密钥:
tencent:
secretId: 你的腾讯云SecretId
secretKey: 你的腾讯云SecretKey