May 18, 2021 WeChat Mini Program Development Document
Globally unique recording manager
Listen for recording error events
The callback function that recorded the error event
Property | Type | Description |
---|---|---|
errMsg | string | The error message |
Listen for file events that have finished recording the specified frame size. If frameSize is set, this event is recalled.
Compatible processing of file events that have been recorded at the specified frame size.
Property | Type | Description |
---|---|---|
frameBuffer | ArrayBuffer | Recorded shrapned data |
isLastFrame | boolean | The last frame before the end of the current frame's normal recording |
The base library 2.3.0 starts to support, and the lower version needs to be compatible.
Listening to recordings is interrupted by the start event because it is occupied by the system. T his event is triggered by the following scenarios: WeChat voice chat, WeChat video chat. W hen this event is triggered, the recording is paused. The pause event is triggered after this event
The callback function that interrupts the start event because the recording is occupied by the system
The base library 2.3.0 starts to support, and the lower version needs to be compatible.
Listen to the recording interrupt end event. After receiving the sessionBegin event, all recordings within the program are paused until the event is received.
The callback function for the recording interrupt end event
Listen for recording pause events
The callback function for recording pause events
Listen to the recording to continue the event
The callback function of the recording continues the event
Listen to the recording to start the event
The callback function for recording the start event
Listen to the recording to end the event
The callback function for recording the end event
Property | Type | Description |
---|---|---|
tempFilePath | string | Temporary path to recording file (local path) |
duration | number | Total recording time, in ms |
fileSize | number | Record file size, in Byte |
Pause the recording
Continue recording
Start recording
Property | Type | The default | Required | Description | The lowest version |
---|---|---|---|---|---|
duration | number | 60000 | Whether | Recording length, ms, maximum 600000 (10 minutes) | |
sampleRate | number | 8000 | Whether | The sample rate | |
numberOfChannels | number | 2 | Whether | The number of recording channels | |
encodeBitRate | number | 48000 | Whether | Code rate, valid value can be found in the table below | |
format | string | Aac | Whether | Audio format | |
frameSize | number | Whether | Specify the frame size in KB. W hen frameSize is passed in, the recorded file content is thrased for each recording of the specified frame size, and no callback is made without specifying it. Only the mp3 format is currently supported. | ||
audioSource | string | auto | Whether | Specify the audio input source for the recording, and you can get the currently available audio source through wx.getAvailableAudioSources(). | 2.1.0 |
The legal value of object.sampleRate
Value | Description | The lowest version |
---|---|---|
8000 | 8000 sample rate | |
11025 | 11025 sample rate | |
12000 | 12000 sample rate | |
16000 | 16000 sample rate | |
22050 | 22050 sample rate | |
24000 | 24000 sample rate | |
32000 | 32000 sample rate | |
44100 | 44100 sample rate | |
48000 | 48000 sample rate |
The legal value of object.numberOfChannels
Value | Description | The lowest version |
---|---|---|
1 | 1 channel | |
2 | 2 channels |
The legal value of object.format
Value | Description | The lowest version |
---|---|---|
mp3 | mp3 format | |
Aac | aac format | |
Wav | Wav format | |
Pcm | pcm format |
The legal value of object.audioSource
Value | Description | The lowest version |
---|---|---|
auto | Automatic settings, the default use of mobile phone microphone, plug in the headset and automatically switch the use of headphone microphone, all platforms apply | |
buildInMic | Mobile microphone, iOS only | |
headsetMic | Headset microphone, iOS only | |
Mic | Microphones (phone microphones when you don't have a headset, headphone microphones when you plug in your headset), Android only | |
camcorder | Same mic for recording audio and video content, Android only | |
voice_communication | With mic, for real-time communication, Android only | |
voice_recognition | Same mic, for speech recognition, Android only |
Each sample rate has a valid value for the code rate range, and setting an illegal sample rate or code rate can cause the recording to fail, as shown in the table below.
The sample rate | Code rate |
---|---|
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 recording
const recorderManager = wx.getRecorderManager()
recorderManager.onStart(() => {
console.log('recorder start')
})
recorderManager.onPause(() => {
console.log('recorder pause')
})
recorderManager.onStop((res) => {
console.log('recorder stop', res)
const { tempFilePath } = res
})
recorderManager.onFrameRecorded((res) => {
const { frameBuffer } = res
console.log('frameBuffer.byteLength', frameBuffer.byteLength)
})
const options = {
duration: 10000,
sampleRate: 44100,
numberOfChannels: 1,
encodeBitRate: 192000,
format: 'aac',
frameSize: 50
}
recorderManager.start(options)