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
Properties Type Default value Required Description success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) object.success callback function parameters: Object res。
Properties Type Description tempFilePath string Temporary path of the recording file (local path) Sample code:
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
Properties Type Default value Required Description success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) Sample code:
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.
Properties Type Description errMsg string Error 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.
Properties Type Description frameBuffer ArrayBuffer Recording fragment data isLastFrame boolean Whether 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.
Properties Type Description tempFilePath string Temporary path of the recording file (local path) duration number Total recording duration, unit: ms fileSize number Recording 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
Properties Type Default value Required Description duration number 60000 No The duration of the recording, in ms, with a maximum value of 600000 (10 minutes) sampleRate number 80000 No Sampling rate (not supported on PC) numberOfChannels number 2 No Number of recording channels encodeBitRate number 48000 No Encoding bitrate, see the table below for valid values format string aac No Audio format frameSize number - No Specify 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 audioSource string auto No Specify the audio input source for recording Legal values
Legal value Description 1 8 channel 2 9 channels Legal values
Legal value Description mp3 mp3 format aac aac format wav wav format PCM pcm format Legal values
Legal value Description auto Automatically set, use the mobile phone microphone by default, and automatically switch to the headphone microphone after plugging in the headset, applicable to all platforms buildInMic Mobile phone microphone, iOS only headsetMic Wired headphone microphone, iOS only mic Microphone (mobile phone microphone when no headset is plugged in, headphone microphone when headset is plugged in), Android only camcorder Same as mic, suitable for recording audio and video content, Android only voice_communication Same as mic, suitable for real-time communication, Android only voice_recognition Same 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 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
TIP
The API usage is as follows: RecorderManager.stop()
- Functional description: Stop recording