Skip to content

初始化

方法名

initializeSambertTts

注意

识别结果会在该方法中回调

用法

  • 用法如下:
js
module.initializeSambertTts({
  params: {
    //url
    url: "wss://dashscope.aliyuncs.com/api-ws/v1/inference",
    //必填, 推荐填入具有唯一性的id, 方便定位问题
    deviceId: "empty_device_id",
    //debug目录
    debugDir: "/storage/emulated/0/alyNui/debug",
    //表示是否保存音频debug,该数据保存在debugDir目录中
    saveWav: true
    //更多参数请参考插件文档
  },
  //成功执行的函数
  success: (res) => {
    console.log(res)
  },
  //失败执行的函数
  fail: (res) => {
    console.log(res)
  },
  //接口调用完成返回函数,不管成功还是失败都会返回
  // complete: (res) => {
  //   console.log(res)
  // }
})
js
module.initializeSambertTts({
  params: {
    //url
    url: "wss://dashscope.aliyuncs.com/api-ws/v1/inference",
    //必填, 推荐填入具有唯一性的id, 方便定位问题
    deviceId: "empty_device_id",
    //debug目录
    debugDir: "/storage/emulated/0/alyNui/debug",
    //表示是否保存音频debug,该数据保存在debugDir目录中
    saveWav: true
    //更多参数请参考插件文档
  },
  //成功执行的函数
  success: (res) => {
    console.log(res)
  },
  //失败执行的函数
  fail: (res) => {
    console.log(res)
  },
  //接口调用完成返回函数,不管成功还是失败都会返回
  // complete: (res) => {
  //   console.log(res)
  // }
} as LevenOptions)
  • 参数说明
    参数名参数类型是否必填默认值参数描述
    paramsObject接口请求参数
    params.deviceIdString必填, 推荐填入具有唯一性的id, 方便定位问题
    params.urlString服务地址,推荐终端用户使用就近地域接入域名
    params.debugDirStringdebug目录
    params.saveWavBooleanfalse是否保存音频debug,数据保存在debugDir中
    params.maxLogFileSizeLong设置本地存储日志文件的最大字节数, 最大将会在本地存储2个设置字节大小的日志文件
    successFunction执行成功的函数
    failFunction执行失败的函数
    completeFunction执行完成的函数,不管成功还是失败都会执行

回调

  • 示例
json
{
    "data": {
        "type": "onInitSuccess"
    },
    "message": "",
    "code": 0
}
json
{
    "data": {
        "type": "playStart"
    },
    "message": "",
    "code": 0
}
json
{
    "data": {
        "type": "playOver"
    },
    "message": "",
    "code": 0
}
json
{
  "data": {
      "retCode": 0,
      "type": "onTtsEventCallback",
      "eventName": "TTS_EVENT_END",
      "taskId": "e2b7f536a27740ae984065d4e458595f",
      "audioFilePath": "/storage/emulated/0/alyNui/audio/tts_task_id_e2b7f536a27740ae984065d4e458595f.pcm",
      "eventCode": 1
  },
  "message": "",
  "code": 0
}
  • 回调说明:
    参数名参数类型参数描述
    messageString消息提示
    dataObject数据对象
    data.typeString类型
    onInitSuccess:初始化成功
    playStart:开始播放
    playOver:播放结束
    onTtsEventCallback:合成过程回调
    data.retCodeString回调状态码
    data.eventNameString事件类型
    data.taskIdString任务ID
    data.eventCodeInteger事件状态码
    data.audioFilePathString保存文件路径
    codeInteger返回类型,0.成功,其他:失败