Appearance
开始合成流式语音合成
方法名
startStreamInputTts
用法
- 用法如下:
js
//合成的文本列表
let sentences = this.form.text.split("\n");
module.startStreamInputTts({
params: {
//自定义sessionId
sessionId: "",
//合成的文本列表
sentences: sentences,
//是否保存音频文件
saveAudio: this.form.saveAudio,
//音频文件保存目录,可以为空
audioDir: "/storage/emulated/0/alyNui/audio",
//文件保存类型
saveType: this.form.format,
//appKey
appKey: AppConfig.appKey,
//token
token: AppConfig.token,
//url
url: AppConfig.url,
//debug目录
debugDir: "/storage/emulated/0/alyNui/debug",
//设置本地存储日志文件的最大字节数, 最大将会在本地存储2个设置字节大小的日志文件
maxLogFileSize: 50 * 1024 * 1024,
//开启字级别时间戳。更多使用方法,请参见https://help.aliyun.com/zh/isi/developer-reference/timestamp-overview-1?spm=a2c4g.11186623.0.0.6b2744871WHhM1
enableSubtitle: true,
//发音人
voice: this.form.voice,
//音频编码格式
format: this.form.format,
//是否打开内部解码器,若设置mp3/opus格式, 可enable_audio_decoder打开内部解码器, 将mp3/opus编码成pcm
enableAudioDecoder: this.form.format == "mp3" || this.form.format == "opus",
//音频采样率,24000,可选择8000、16000、24000、48000。
sampleRate: 16000,
//音量
volume: this.form.volume,
//朗读语速
speechRate: this.form.speechRate,
//朗读语调
pitchRate: this.form.pitchRate
},
//成功执行的函数
success: (res) => {
// console.log(res)
let data = res.data;
if (data && data.eventName == "STREAM_INPUT_TTS_EVENT_SYNTHESIS_COMPLETE" && data.audioFilePath) {
let audioFilePath = data.audioFilePath;
uni.showToast({
title: "文件保存路径:" + audioFilePath,
icon: "none",
duration: 5000
})
}
},
//失败执行的函数
fail: (res) => {
console.log(res)
},
//接口调用完成返回函数,不管成功还是失败都会返回
// complete: (res) => {
// console.log(res)
// }
})js
//合成的文本列表
const sentences = text.value.split("\n");
module.startStreamInputTts({
params: {
//自定义sessionId
sessionId: "",
//合成的文本列表
sentences: sentences,
//是否保存音频文件
saveAudio: saveAudio.value,
//音频文件保存目录,可以为空
audioDir: "/storage/emulated/0/alyNui/audio",
//文件保存类型
saveType: format.value,
//appKey
appKey: AppConfig.appKey,
//token
token: AppConfig.token,
//url
url: AppConfig.url,
//debug目录
debugDir: "/storage/emulated/0/alyNui/debug",
//设置本地存储日志文件的最大字节数, 最大将会在本地存储2个设置字节大小的日志文件
maxLogFileSize: 50 * 1024 * 1024,
//开启字级别时间戳。更多使用方法,请参见https://help.aliyun.com/zh/isi/developer-reference/timestamp-overview-1?spm=a2c4g.11186623.0.0.6b2744871WHhM1
enableSubtitle: true,
//发音人
voice: voice.value,
//音频编码格式
format: format.value,
//是否打开内部解码器,若设置mp3/opus格式, 可enable_audio_decoder打开内部解码器, 将mp3/opus编码成pcm
enableAudioDecoder: format.value == "mp3" || format.value == "opus",
//音频采样率,24000,可选择8000、16000、24000、48000。
sampleRate: 16000,
//音量
volume: volume.value,
//朗读语速
speechRate: speechRate.value,
//朗读语调
pitchRate: pitchRate.value
},
//成功执行的函数
success: (res) => {
// console.log(res)
const data = res.data;
const eventName = data.getString("eventName")
const audioFilePath = data.getString("audioFilePath")
if (eventName == "STREAM_INPUT_TTS_EVENT_SYNTHESIS_COMPLETE" && audioFilePath != null) {
uni.showToast({
title: "文件保存路径:" + audioFilePath,
icon: "none",
duration: 5000
})
}
},
//失败执行的函数
fail: (res) => {
console.log(res)
},
//接口调用完成返回函数,不管成功还是失败都会返回
// complete: (res) => {
// console.log(res)
// }
} as LevenOptions)- 参数说明
参数名 参数类型 是否必填 默认值 参数描述 params Object 是 无 接口请求参数 params.sessionId String 否 无 自定义sessionId params.sentences String[] 是 无 合成的文本列表 params.saveAudio Boolean 否 false 是否保存音频文件 params.audioDir String 是 无 音频文件保存目录,可以为空 params.saveType String 否 无 文件保存类型,可选值: pcmwavparams.appKey String 否 无 申请的应用appKey params.token String 否 无 申请的应用token params.accessKey String 否 无 申请的应用accessKey params.accessKeySecret String 否 无 申请的应用accessKeySecret params.stsToken String 否 无 申请的应用stsToken params.url String 是 无 请求地址 params.debugDir String 否 无 debug目录 params.maxLogFileSize Integer 否 无 设置本地存储日志文件的最大字节数, 最大将会在本地存储2个设置字节大小的日志文件 params.enableSubtitle Boolean 否 false 开启字级别时间戳。更多使用方法,请参见https://help.aliyun.com/zh/isi/developer-reference/timestamp-overview-1?spm=a2c4g.11186623.0.0.6b2744871WHhM1 params.voice String 否 无 发音人 params.format String 否 无 音频编码格式,可选值: pcmwavparams.enableAudioDecoder Boolean 否 false 是否打开内部解码器,若设置mp3/opus格式, 可enable_audio_decoder打开内部解码器, 将mp3/opus编码成pcm params.sampleRate Integer 否 16000 音频采样率,默认值:16000Hz。根据音频采样率在管控台对应项目中配置支持该采样率及场景的模型,可选值:8000、16000、24000、48000 params.volume Integer 否 50 范围是0~100 params.speechRate Integer 否 0 朗读语速,范围是-500~500 params.pitchRate Integer 否 0 朗读语调,范围是-500~500 success Function 否 无 执行成功的函数 fail Function 否 无 执行失败的函数 complete Function 否 无 执行完成的函数,不管成功还是失败都会执行
回调
- 示例
json
{
"data": {
"type": "startSuccess"
},
"message": "",
"code": 0
}json
{
"data": {
"type": "playStart"
},
"message": "",
"code": 0
}json
{
"data": {
"type": "playOver"
},
"message": "",
"code": 0
}json
{
"data": {
"errorMsg": "Gateway:SUCCESS:Success.",
"taskId": "042ee4f7c4bd4fab91815c705e26644e",
"timestamp": "",
"allResponse": "{\"header\":{\"namespace\":\"FlowingSpeechSynthesizer\",\"name\":\"SynthesisStarted\",\"status\":20000000,\"message_id\":\"2b6b2e5bf67a4a30957ee96447fcfe33\",\"task_id\":\"042ee4f7c4bd4fab91815c705e26644e\",\"status_text\":\"Gateway:SUCCESS:Success.\"}}",
"type": "onStreamInputTtsEventCallback",
"eventName": "STREAM_INPUT_TTS_EVENT_SYNTHESIS_STARTED",
"retCode": 20000000,
"sessionId": "",
"audioFilePath": "/storage/emulated/0/alyNui/audio/tts_task_id_042ee4f7c4bd4fab91815c705e26644e.pcm",
"eventCode": 0
},
"message": "",
"code": 0
}- 回调说明:
参数名 参数类型 参数描述 message String 消息提示 data Object 数据对象 data.type String 回调类型: startSuccess:开启成功playStart:开始播放playOver:结束播放onStreamInputTtsEventCallback:流式语音合成回调data.errorMsg String 错误类型 data.taskId String 任务id data.timestamp String 时间戳 data.allResponse String 响应数据 data.eventName String 回调事件类型 data.retCode String - data.sessionId String 自定义sessionId data.audioFilePath String 音频保存本地文件路径 data.eventCode String 回调事件code值 code Integer 返回类型,0.成功,其他:失败
