Skip to main content
Version: 3.x

Taro.playVoice(option)

Starts the playback of a voice file. Only one file can be played at a time. The start of the playback of a file will stops the in-progress playback of the previous one.

Reference

Type

(option: Option) => Promise<CallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
filePathstringYesThe path of the voice file to be played
durationnumberNoSpecifies the recording duration (in sec). The recording stops automatically when the specified number of seconds elapse.
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

Sample Code

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

API Support

APIWeChat Mini-ProgramH5React Native
Taro.playVoice✔️