RecorderManager.start
Introduction
Starts recording audio.
Usage Restrictions
Supported in the basic library version 4.0.0
or higher.
Parameters
Object object
Property | Type | Default | Required | Description |
---|---|---|---|---|
duration | number | 60000 | No | The duration of the recording in milliseconds, with a maximum value of 600000 (10 minutes). |
sampleRate | number | 8000 | No | The sample rate (not supported on PC). Valid values are listed in the Valid Sample Rates (sampleRate) table below. |
numberOfChannels | number | 2 | No | The number of audio channels. You can pass 1 or 2. |
encodeBitRate | number | 48000 | No | The encoding bit rate. Valid values are listed in the Sample Rates and Encoding Bit Rates Limitations table below. |
format | string | aac | No | The audio format. Only "aac" is supported. |
audioSource | string | auto | No | Specifies the audio input source for recording. You can obtain the currently available audio sources through dlt.getAvailableAudioSources(). |
success | function | No | Callback function for a successful API invocation. | |
fail | function | No | Callback function for a failed API invocation. | |
complete | function | No | Callback function that is called at the end of the API invocation (whether it was successful or failed). |
Valid Sample Rates (sampleRate)
Value | Description |
---|---|
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. |
Sample Rates and Encoding Bit Rates Limitations
Each sample rate corresponds to a valid range of encoding bit rates. Setting an invalid sample rate or encoding bit rate will result in a recording failure. The specific correspondence is shown in the table below:
Sample Rate | Encoding Bit Rate Range |
---|---|
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. |
object.success Callback Function Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | true - Success |
object.fail Callback Function Parameters
Object res
Property | Type | Description |
---|---|---|
errMsg | string | Error message |
success | string | false - Failure |
errMsg Description
Error Message | Description |
---|---|
Parameter error: A10001 | Invalid parameter |
Invalid sampleRate "sampleRate", sampleRate should be one of ${availableSampleRate}: A10002 | sampleRate parameter value is not in the valid range |
Invalid numberOfChannels ${numberOfChannels}, numberOfChannels should be one of ${availableChannels} : A10003 | numberOfChannels parameter value is not in the valid range |
Invalid encodeBitRate "encodeBitRate", encodeBitRate should be greater than $min and less than $max : A10004 | encodeBitRate parameter value is not in the valid range |
Invalid format "format", format should be one of ${availableRecordingFormat} : A10005 | format parameter value is not in the valid range |
Invalid audioSource "audioSource", audioSource should be one of ${availableAudioSources} : A10006 | audioSource parameter value is not in the valid range |
Invalid duration $duration, duration should be between 0 and $maxDuration : A10007 | duration parameter value is not in the valid range |
Audio is recording, don't start record again : A10008 | Recording is in progress, please do not start again |
Audio is paused, start record fail : A10009 | Recording is paused, starting recording failed |
create record file is fail : A10010 | Failed to create a recording file |
Audio failed with permission denied : A10011 | No recording permission |
Example
// pages/index/index.js
Page({
start() {
const recorderManager = dlt.getRecorderManager();
const options = {
duration: 10000,
sampleRate: 44100,
numberOfChannels: 1,
encodeBitRate: 192000,
format: 'aac',
};
recorderManager.start(options);
},
});
In this example, the RecorderManager
is used to start recording audio. The start
method is called with various recording options, and you can handle the recording events by setting up event listeners as needed.