Skip to content

Recording

startRecord

TIP

The API usage is as follows: wx.startRecord(Object object)

  • Functional description: Start recording. When actively called wx.stopRecord , or when the recording exceeds 1 minute, the recording will automatically end. When the user leaves the mini program, this interface cannot be called.

  • Parameters and descriptions: Object object

    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • object.success callback function parameters: Object res。

    PropertiesTypeDescription
    tempFilePathstringTemporary path of the recording file (local path)
  • Sample code:

js
wx.startRecord({
  success (res) {
    const tempFilePath = res.tempFilePath
  }
})
setTimeout(function () {
  wx.stopRecord() // Stop audio recording
}, 10000)

stopRecord

TIP

The API usage is as follows: wx.stopRecord(Object object)

  • Functional description: Stop recording

  • Parameters and descriptions: Object object

    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • Sample code:

js
wx.startRecord({
  success (res) {
    const tempFilePath = res.tempFilePath
  }
})
setTimeout(function () {
  wx.stopRecord() // Stop audio recording
}, 10000)

getRecorderManager

TIP

The API usage is as follows: RecorderManager wx.getRecorderManager()

  • Functional description: Get the globally unique recording manager RecorderManager.
  • Return value: RecorderManager

RecorderManager

.onError

TIP

The API usage is as follows: RecorderManager.onError(function listener)

  • Functional description: Listen for recording error events.
  • Parameters and descriptions: function listener, Listening function for recording error events, Object res parameter.
    PropertiesTypeDescription
    errMsgstringError message

.onFrameRecorded

TIP

The API usage is as follows: RecorderManager.onFrameRecorded(function listener)

  • Functional description: Listen for the event that the file with the specified frame size has been recorded. If frameSize is set, this event will be called back.
  • Parameters and descriptions: function listener, Listening function for the event that the file with the specified frame size has been recorded, Object res parameter.
    PropertiesTypeDescription
    frameBufferArrayBufferRecording fragment data
    isLastFramebooleanWhether the current frame is the last frame before the recording ends normally

.onInterruptionBegin

TIP

The API usage is as follows: RecorderManager.onInterruptionBegin(function listener)

  • Functional description: Listen for the event that the recording is interrupted due to system occupation. The following scenarios will trigger this event: Luffa voice chat, Luffa video chat. After this event is triggered, the recording will be paused. The pause event is triggered after this event.
  • Parameters and descriptions: function listener, Listening function for the event that the recording is interrupted due to system occupation.

.onInterruptionEnd

TIP

The API usage is as follows: RecorderManager.onInterruptionEnd(function listener)

  • Functional description: Listen for the event that the recording is interrupted due to system occupation. After receiving the interruptionBegin event, all recordings in the applet will be paused. Recording can only be successfully resumed after receiving this event.
  • Parameters and descriptions: function listener, Listening function for recording interruption end event.

.onPause

TIP

The API usage is as follows: RecorderManager.onPause(function listener)

  • Functional description: Listening for recording pause event.
  • Parameters and descriptions: function listener, Listening for recording pause event.

.onResume

TIP

The API usage is as follows: RecorderManager.onResume(function listener)

  • Functional description: Listening for recording continuation event.
  • Parameters and descriptions: function listener, Listening for recording continuation event.

.onStart

TIP

The API usage is as follows: RecorderManager.start(Object object)

  • Functional description: Listening for recording start event.
  • Parameters and descriptions: function listener, Listening for recording start event.

.onStop

TIP

The API usage is as follows: RecorderManager.onStop(function listener)

  • Functional description: Listening for recording end event.

  • Parameters and descriptions: function listener, Listening for recording end event. Object res parameter.

    PropertiesTypeDescription
    tempFilePathstringTemporary path of the recording file (local path)
    durationnumberTotal recording duration, unit: ms
    fileSizenumberRecording file size, unit: Byte

.pause

TIP

The API usage is as follows: RecorderManager.pause()

  • Functional description: Pause recording.

.resume

TIP

The API usage is as follows: RecorderManager.resume()

  • Functional description: Continue recording.

.start

TIP

The API usage is as follows: RecorderManager.start(Object object)

  • Functional description: Start recording

  • Parameters and descriptions: Object object

    PropertiesTypeDefault valueRequiredDescription
    durationnumber60000NoThe duration of the recording, in ms, with a maximum value of 600000 (10 minutes)
    sampleRatenumber80000NoSampling rate (not supported on PC)
    numberOfChannelsnumber2NoNumber of recording channels
    encodeBitRatenumber48000NoEncoding bitrate, see the table below for valid values
    formatstringaacNoAudio format
    frameSizenumber-NoSpecify the frame size, in KB. After passing in frameSize, the recorded file content will be called back after each recording of the specified frame size. If not specified, it will not be called back. Only mp3 and pcm formats are supported for now
    audioSourcestringautoNoSpecify the audio input source for recording
  • Legal values

    Legal valueDescription
    13 channel
    24 channels
  • Legal values

    Legal valueDescription
    mp3mp3 format
    aacaac format
    wavwav format
    PCMpcm format
  • Legal values

    Legal valueDescription
    autoAutomatically set, use the mobile phone microphone by default, and automatically switch to the headphone microphone after plugging in the headset, applicable to all platforms
    buildInMicMobile phone microphone, iOS only
    headsetMicWired headphone microphone, iOS only
    micMicrophone (mobile phone microphone when no headset is plugged in, headphone microphone when headset is plugged in), Android only
    camcorderSame as mic, suitable for recording audio and video content, Android only
    voice_communicationSame as mic, suitable for real-time communication, Android only
    voice_recognitionSame as mic, for speech recognition, only for Android
  • Sampling rate and encoding bitrate limit

    Each sampling rate has a corresponding valid value of the encoding bitrate range. Setting an illegal sampling rate or encoding bitrate will cause recording failure. The specific correspondence is shown in the following table.

    Sampling rateEncoding bitrate
    800016000 ~ 48000
    1102516000 ~ 48000
    1200024000 ~ 64000
    1600024000 ~ 96000
    2205032000 ~ 128000
    2400032000 ~ 128000
    3200048000 ~ 192000
    4410064000 ~ 320000
    4800064000 ~ 320000

.stop

TIP

The API usage is as follows: RecorderManager.stop()

  • Functional description: Stop recording