Skip to main content
Version: 2.x

Taro.playVoice(option)

开始播放语音。同时只允许一个语音文件正在播放,如果前一个语音文件还没播放完,将中断前一个语音播放。

参考文档

类型

(option: Option) => Promise<CallbackResult>

参数

Option

参数类型必填说明
filePathstring需要播放的语音文件的文件路径
complete(res: CallbackResult) => void接口调用结束的回调函数(调用成功、失败都会执行)
durationnumber指定录音时长,到达指定的录音时长后会自动停止录音,单位:秒
fail(res: CallbackResult) => void接口调用失败的回调函数
success(res: CallbackResult) => void接口调用成功的回调函数

示例代码

Taro.startRecord({
success: function (res) {
const tempFilePath = res.tempFilePath
Taro.playVoice({
filePath: tempFilePath,
complete: function () { }
})
}
})

API 支持度

API微信小程序H5React Native
Taro.playVoice✔️