HomeDocs
Skip to main content

RecorderManager.start

Introduction

Starts recording audio.

Usage Restrictions

Supported in the basic library version 4.0.0 or higher.

Parameters

Object object

PropertyTypeDefaultRequiredDescription
durationnumber60000NoThe duration of the recording in milliseconds, with a maximum value of 600000 (10 minutes).
sampleRatenumber8000NoThe sample rate (not supported on PC). Valid values are listed in the Valid Sample Rates (sampleRate) table below.
numberOfChannelsnumber2NoThe number of audio channels. You can pass 1 or 2.
encodeBitRatenumber48000NoThe encoding bit rate. Valid values are listed in the Sample Rates and Encoding Bit Rates Limitations table below.
formatstringaacNoThe audio format. Only "aac" is supported.
audioSourcestringautoNoSpecifies the audio input source for recording. You can obtain the currently available audio sources through dlt.getAvailableAudioSources().
successfunctionNoCallback function for a successful API invocation.
failfunctionNoCallback function for a failed API invocation.
completefunctionNoCallback function that is called at the end of the API invocation (whether it was successful or failed).

Valid Sample Rates (sampleRate)

ValueDescription
80008000 sample rate.
1102511025 sample rate.
1200012000 sample rate.
1600016000 sample rate.
2205022050 sample rate.
2400024000 sample rate.
3200032000 sample rate.
4410044100 sample rate.
4800048000 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 RateEncoding Bit Rate Range
800016000 ~ 48000.
1102516000 ~ 48000.
1200024000 ~ 64000.
1600024000 ~ 96000.
2205032000 ~ 128000.
2400032000 ~ 128000.
3200048000 ~ 192000.
4410064000 ~ 320000.
4800064000 ~ 320000.

object.success Callback Function Parameters

Object res

PropertyTypeDescription
successstringtrue - Success

object.fail Callback Function Parameters

Object res

PropertyTypeDescription
errMsgstringError message
successstringfalse - Failure

errMsg Description

Error MessageDescription
Parameter error: A10001Invalid parameter
Invalid sampleRate "sampleRate", sampleRate should be one of ${availableSampleRate}: A10002sampleRate parameter value is not in the valid range
Invalid numberOfChannels ${numberOfChannels}, numberOfChannels should be one of ${availableChannels} : A10003numberOfChannels parameter value is not in the valid range
Invalid encodeBitRate "encodeBitRate", encodeBitRate should be greater than $min and less than $max : A10004encodeBitRate parameter value is not in the valid range
Invalid format "format", format should be one of ${availableRecordingFormat} : A10005format parameter value is not in the valid range
Invalid audioSource "audioSource", audioSource should be one of ${availableAudioSources} : A10006audioSource parameter value is not in the valid range
Invalid duration $duration, duration should be between 0 and $maxDuration : A10007duration parameter value is not in the valid range
Audio is recording, don't start record again : A10008Recording is in progress, please do not start again
Audio is paused, start record fail : A10009Recording is paused, starting recording failed
create record file is fail : A10010Failed to create a recording file
Audio failed with permission denied : A10011No 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.

Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.