title: Taro.playVoice(option)

sidebar_label: playVoice

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

  1. (option: Option) => Promise<CallbackResult>

Parameters

Option

Property Type Required Description
filePath string Yes The path of the voice file to be played
duration number No Specifies the recording duration (in sec). The recording stops automatically when the specified number of seconds elapse.
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

Sample Code

  1. Taro.startRecord({
  2. success: function (res) {
  3. const tempFilePath = res.tempFilePath
  4. Taro.playVoice({
  5. filePath: tempFilePath,
  6. complete: function () { }
  7. })
  8. }
  9. })

API Support

API WeChat Mini-Program H5 React Native
Taro.playVoice ✔️