tencent cloud

Feedback

Audio recording

Last updated: 2024-03-05 15:08:29

    startRecord

    This API is used via wx.startRecord(Object object).
    Feature Description: Starts audio recording. The audio recording will automatically cease when wx.stopRecord is actively invoked, or when the audio recording exceeds one minute. This interface cannot be invoked when the user exits the mini program.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    tempFilePath
    string
    Temporary path of audio recording file (local path)
    Sample Code
    wx.startRecord({
    success (res) {
    const tempFilePath = res.tempFilePath
    }
    })
    setTimeout(function () {
    wx.stopRecord() // Stop audio recording
    }, 10000)

    stopRecord

    This API is used via wx.stopRecord(Object object).
    Feature Description: Stops audio recording.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.startRecord({
    success (res) {
    const tempFilePath = res.tempFilePath
    }
    })
    setTimeout(function () {
    wx.stopRecord() // Stop audio recording
    }, 10000)

    getRecorderManager

    This API is used via RecorderManager wx.getRecorderManager().
    Feature Description: Gets the globally unique RecorderManager.
    Return Value: RecorderManager.

    RecorderManager

    .onError

    This method is used via RecorderManager.onError(function listener).
    Feature Description: Monitors audio recording error events.
    Parameter and Description: function listener, the listener function for audio recording error events.
    Attribute
    Type
    Description
    errMsg
    string
    Error Message

    .onFrameRecorded

    This method is used via RecorderManager.onFrameRecorded(function listener).
    Feature Description: Monitors events where files have been recorded to a specified frame size. If frameSize is set, this event will be called back.
    Parameter and Description: function listener, the listener function for events where files have been recorded to a specified frame size.
    Attribute
    Type
    Description
    frameBuffer
    ArrayBuffer
    Audio recording shard data
    isLastFrame
    boolean
    Is the current frame the last one before the normal end of the audio recording?

    .onInterruptionBegin

    This method is used via RecorderManager.onInterruptionBegin(function listener).
    Feature Description: Monitors events where audio recording is interrupted due to system occupation. WeChat voice chat and WeChat video chat scenarios will trigger such events, and subsequently the audio recording will pause.
    Parameter and Description: function listener, the listener function for events where audio recording is interrupted due to system occupation.

    .onInterruptionEnd

    This method is used via RecorderManager.onInterruptionEnd(function listener).
    Feature Description: Monitors audio recording interruption ending events. After receiving the interruptionBegin event, all audio recordings within the mini program will pause, and only after receiving this event can audio recording be successfully resumed.
    Parameter and Description: function listener, the listener function for audio recording interruption ending events.

    .onPause

    This method is used via RecorderManager.onPause(function listener).
    Feature Description: Monitors audio recording pause events.
    Parameter and Description: function listener, the listener function for audio recording pause events.

    .onResume

    This method is used via RecorderManager.onResume(function listener).
    Feature Description: Monitors audio recording continuation events.
    Parameter and Description: function listener, the listener function for audio recording continuation events.

    .onStart

    This method is used via RecorderManager.start(Object object).
    Feature Description: Monitors audio recording start events.
    Parameter and Description: function listener, the listener function for audio recording start events.

    .onStop

    This method is used via RecorderManager.onStop(function listener).
    Feature Description: Monitors audio recording ending events.
    Parameters and Description: function listener, the listener function for audio recording ending events. Object res parameter.
    Attribute
    Type
    Description
    tempFilePath
    string
    Temporary path of audio recording file (local path)
    duration
    number
    Total audio recording duration, in milliseconds.
    fileSize
    number
    Audio recording file size, in bytes.

    .pause

    This method is used via RecorderManager.pause().
    Feature Description: Pauses audio recording.

    .resume

    This method is used via RecorderManager.resume().
    Feature Description: Continues audio recording.

    .start

    This method is used via RecorderManager.start(Object object).
    Feature Description: Starts audio recording.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    duration
    number
    60000
    No
    The duration of the audio recording, measured in milliseconds (ms), with a maximum value of 600,000 (equivalent to 10 minutes).
    sampleRate
    number
    80000
    No
    Sampling rate (not supported on PC)
    numberOfChannels
    number
    2
    No
    Number of audio recording channels
    encodeBitRate
    number
    48000
    No
    Encoding bitrate, with valid values provided in the table below.
    format
    string
    aac
    No
    Audio Format
    frameSize
    number
    -
    No
    Specify the frame size in kilobytes (KB). Upon passing in the frameSize, the content of the files recorded to the specified frame size will be called back. If not specified, no callback will occur. Currently, only mp3 and pcm formats are supported.
    audioSource
    string
    auto
    No
    Specify the audio input source for audio recording.
    Sampling rate and encoding bitrate limits
    Each sampling rate corresponds to a valid range of encoding bitrates. Setting an invalid sampling rate or encoding bitrate will result in audio recording failure. The specific correspondences are as follows in the table.
    Sampling rate.
    Encoding bitrate
    8000
    16000 ~ 48000
    11025
    16000 ~ 48000
    12000
    24000 ~ 64000
    16000
    24000 ~ 96000
    22050
    32000 ~ 128000
    24000
    32000 ~ 128000
    32000
    48000 ~ 192000
    44100
    64000 ~ 320000
    48000
    64000 ~ 320000

    .stop

    This method is used via RecorderManager.stop().
    Feature Description: Pauses audio recording.
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support