HomeDocs
跳到主要内容

RecorderManager.start

简介​

开始录音。

使用限制​

基础库 4.0.0 或更高版本支持。

参数​

Object object

属性类型默认值必填说明
durationnumber60000否录音的时长,单位 ms,最大值 600000(10 分钟)
sampleRatenumber8000否采样率(pc 不支持)有效值见下方 采样率(sampleRate)的合法值 表
numberOfChannelsnumber2否录音通道数。可传 1 或 2
encodeBitRatenumber48000否编码码率。有效值见下方 采样率与编码码率限制 表。
formatstringaac否音频格式。仅支持 aac
audioSourcestringauto否指定录音的音频输入源,可通过 dlt.getAvailableAudioSources() 获取当前可用的音频源
successfunction否接口调用成功的回调函数
failfunction否接口调用失败的回调函数
completefunction否接口调用结束的回调函数(调用成功、失败都会执行)

采样率(sampleRate)的合法值​

值说明
80008000 采样率。
1102511025 采样率。
1200012000 采样率。
1600016000 采样率。
2205022050 采样率。
2400024000 采样率。
3200032000 采样率。
4410044100 采样率。
4800048000 采样率。

采样率与编码码率限制​

每种采样率有对应的编码码率范围有效值,设置不合法的采样率或编码码率会导致录音失败,具体对应关系如下表:

采样率编码码率
800016000 ~ 48000。
1102516000 ~ 48000。
1200024000 ~ 64000。
1600024000 ~ 96000。
2205032000 ~ 128000。
2400032000 ~ 128000。
3200048000 ~ 192000。
4410064000 ~ 320000。
4800064000 ~ 320000。

object.success 回调函数​

参数​

Object res​

属性类型说明
successstringtrue-成功

object.fail 回调函数​

参数​

Object res​

属性类型说明
errMsgstring错误信息
successstringfalse-失败

errMsg 说明

错误信息说明
Parameter error: A10001参数不合法
Invalid sampleRate "sampleRate", sampleRate should be one of ${availableSampleRate}: A10002sampleRate 参数值不在可选值范围内
Invalid numberOfChannels ${numberOfChannels}, numberOfChannels should be one of ${availableChannels} : A10003numberOfChannels 参数值不在可选值范围内
Invalid encodeBitRate "encodeBitRate", encodeBitRate should be greater than $min and less than $max : A10004encodeBitRate 参数值不在可选范围内
Invalid format "format", format should be one of ${availableRecordingFormat} : A10005format 参数值不在可选值范围内
Invalid audioSource "audioSource", audioSource should be one of ${availableAudioSources} : A10006audioSource 参数值不在可选值范围内
Invalid duration $duration, duration should be between 0 and $maxDuration : A10007duration 参数值不在可选值范围内
Audio is recording, don't start record again : A10008正在录音中,不要重复开始录音
Audio is paused, start record fail : A10009录音暂停,开始录音失败
create record file is fail : A10010创建录音文件失败
Audio failed with permission denied : A10011没有录音权限

示例代码​

// 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);
},
});
Privacy agreementDeveloper agreementcontact us: developer_private.mi@dlightek.com © 2024 MiniApp. All Rights Reserved.