Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
细水会流长
unidocs-zh
提交
bb1fe1d2
U
unidocs-zh
项目概览
细水会流长
/
unidocs-zh
与 Fork 源项目一致
Fork自
DCloud / unidocs-zh
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bb1fe1d2
编写于
9月 19, 2022
作者:
Anne_LXM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新uni.getRecorderManager平台差异
上级
7a59aa64
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
128 addition
and
125 deletion
+128
-125
docs/api/media/record-manager.md
docs/api/media/record-manager.md
+128
-125
未找到文件。
docs/api/media/record-manager.md
浏览文件 @
bb1fe1d2
### uni.getRecorderManager()
获取
**全局唯一**
的录音管理器
``recorderManager``
。
**平台差异说明**
|App|H5|微信小程序|支付宝小程序|百度小程序|字节跳动小程序、飞书小程序|QQ小程序|快手小程序|京东小程序|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|√|x|√|x|√|√|√|x|√|
**recorderManager 对象的方法列表**
|方法|参数|说明|平台差异说明|
|:-|:-|:-|:-|
|start|options|开始录音||
|pause||暂停录音|App 暂不支持|
|resume||继续录音|App 暂不支持|
|stop||停止录音||
|onStart|callback|录音开始事件||
|onPause|callback|录音暂停事件||
|onStop|callback|录音停止事件,会回调文件地址||
|onFrameRecorded|callback|已录制完指定帧大小的文件,会回调录音分片结果数据。如果设置了 frameSize ,则会回调此事件|App 暂不支持|
|onError|callback|录音错误事件, 会回调错误信息|
|
**start(options) 说明**
|属性|类型|必填|说明|平台差异说明|
|:-|:-|:-|:-|:-|
|duration|Number|否|指定录音的时长,单位 ms ,如果传入了合法的 duration ,在到达指定的 duration 后会自动停止录音,最大值 600000(10 分钟),默认值 60000(1 分钟)|App、小程序支持|
|sampleRate|Number|否|采样率,有效值 8000/16000/44100|App、小程序支持|
|numberOfChannels|Number|否|录音通道数,有效值 1/2|仅小程序支持|
|encodeBitRate|Number|否|编码码率,有效值见下表格|仅小程序支持|
|format|String|否|音频格式,有效值 aac/mp3/wav/PCM。App默认值为mp3,小程序默认值aac|App、小程序支持|
|frameSize|String|否|指定帧大小,单位 KB。传入 frameSize 后,每录制指定帧大小的内容后,会回调录制的文件内容,不指定则不会回调。暂仅支持 mp3 格式。|App、百度小程序不支持|
其中,采样率和码率有一定要求,具体有效值如下:
|采样率|编码码率|
|:-|:-|
|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|
**onStop(callback) 回调结果说明**
|属性|类型|说明|
|:-|:-|:-|
|tempFilePath|String|录音文件的临时路径|
**onFrameRecorded(callback) 回调结果说明**
|属性|类型|说明|
|:-|:-|:-|
|frameBuffer|ArrayBuffer|录音分片结果数据|
|isLastFrame|Boolean|当前帧是否正常录音结束前的最后一帧|
**onError(callback) 回调结果说明**
|属性|类型|说明|
|:-|:-|:-|
|errMsg|String|错误信息|
**注意**
-
可以通过用户授权API来判断用户是否给应用授予麦克风的访问权限
[
https://uniapp.dcloud.io/api/other/authorize
](
https://uniapp.dcloud.io/api/other/authorize
)
**示例**
```
html
<template>
<view>
<button
@
tap=
"startRecord"
>
开始录音
</button>
<button
@
tap=
"endRecord"
>
停止录音
</button>
<button
@
tap=
"playVoice"
>
播放录音
</button>
</view>
</template>
```
```
javascript
const
recorderManager
=
uni
.
getRecorderManager
();
const
innerAudioContext
=
uni
.
createInnerAudioContext
();
innerAudioContext
.
autoplay
=
true
;
export
default
{
data
()
{
return
{
text
:
'
uni-app
'
,
voicePath
:
''
}
},
onLoad
()
{
let
self
=
this
;
recorderManager
.
onStop
(
function
(
res
)
{
console
.
log
(
'
recorder stop
'
+
JSON
.
stringify
(
res
));
self
.
voicePath
=
res
.
tempFilePath
;
});
},
methods
:
{
startRecord
()
{
console
.
log
(
'
开始录音
'
);
recorderManager
.
start
();
},
endRecord
()
{
console
.
log
(
'
录音结束
'
);
recorderManager
.
stop
();
},
playVoice
()
{
console
.
log
(
'
播放录音
'
);
if
(
this
.
voicePath
)
{
innerAudioContext
.
src
=
this
.
voicePath
;
innerAudioContext
.
play
();
}
}
}
}
```
### uni.getRecorderManager()
获取
**全局唯一**
的录音管理器
``recorderManager``
。
**平台差异说明**
|App|H5|微信小程序|支付宝小程序|百度小程序|字节跳动小程序、飞书小程序|QQ小程序|快手小程序|京东小程序|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|√|x|√|x|√|√|√|x|√|
**recorderManager 对象的方法列表**
|方法|参数|说明|平台差异说明|
|:-|:-|:-|:-|
|start|options|开始录音||
|pause||暂停录音|App 暂不支持|
|resume||继续录音|App 暂不支持|
|stop||停止录音||
|onStart|callback|录音开始事件||
|onPause|callback|录音暂停事件||
|onStop|callback|录音停止事件,会回调文件地址||
|onResume|callback|监听录音继续事件|微信小程序、百度小程序、QQ小程序、京东小程序、字节小程序|
|onInterruptionBegin|callback|监听录音因为受到系统占用而被中断开始事件。以下场景会触发此事件:微信语音聊天、微信视频聊天、QQ语音聊天、QQ视频聊天、电话响铃、接听电话。此事件触发后,录音会被暂停。pause 事件在此事件后触发|微信小程序、百度小程序、QQ小程序|
|onInterruptionEnd|callback|监听录音中断结束事件。在收到 interruptionBegin 事件之后,小程序内所有录音会暂停,收到此事件之后才可再次录音成功。|微信小程序、百度小程序、QQ小程序|
|onFrameRecorded|callback|已录制完指定帧大小的文件,会回调录音分片结果数据。如果设置了 frameSize ,则会回调此事件|App 暂不支持|
|onError|callback|录音错误事件, 会回调错误信息|
|
**start(options) 说明**
|属性|类型|必填|说明|平台差异说明|
|:-|:-|:-|:-|:-|
|duration|Number|否|指定录音的时长,单位 ms ,如果传入了合法的 duration ,在到达指定的 duration 后会自动停止录音,最大值 600000(10 分钟),默认值 60000(1 分钟)|App、小程序支持|
|sampleRate|Number|否|采样率,有效值 8000/16000/44100|App、小程序支持|
|numberOfChannels|Number|否|录音通道数,有效值 1/2|仅小程序支持|
|encodeBitRate|Number|否|编码码率,有效值见下表格|仅小程序支持|
|format|String|否|音频格式,有效值 aac/mp3/wav/PCM。App默认值为mp3,小程序默认值aac|App、小程序支持|
|frameSize|String|否|指定帧大小,单位 KB。传入 frameSize 后,每录制指定帧大小的内容后,会回调录制的文件内容,不指定则不会回调。暂仅支持 mp3 格式。|App、百度小程序不支持|
其中,采样率和码率有一定要求,具体有效值如下:
|采样率|编码码率|
|:-|:-|
|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|
**onStop(callback) 回调结果说明**
|属性|类型|说明|
|:-|:-|:-|
|tempFilePath|String|录音文件的临时路径|
**onFrameRecorded(callback) 回调结果说明**
|属性|类型|说明|
|:-|:-|:-|
|frameBuffer|ArrayBuffer|录音分片结果数据|
|isLastFrame|Boolean|当前帧是否正常录音结束前的最后一帧|
**onError(callback) 回调结果说明**
|属性|类型|说明|
|:-|:-|:-|
|errMsg|String|错误信息|
**注意**
-
可以通过用户授权API来判断用户是否给应用授予麦克风的访问权限
[
https://uniapp.dcloud.io/api/other/authorize
](
https://uniapp.dcloud.io/api/other/authorize
)
**示例**
```
html
<template>
<view>
<button
@
tap=
"startRecord"
>
开始录音
</button>
<button
@
tap=
"endRecord"
>
停止录音
</button>
<button
@
tap=
"playVoice"
>
播放录音
</button>
</view>
</template>
```
```
javascript
const
recorderManager
=
uni
.
getRecorderManager
();
const
innerAudioContext
=
uni
.
createInnerAudioContext
();
innerAudioContext
.
autoplay
=
true
;
export
default
{
data
()
{
return
{
text
:
'
uni-app
'
,
voicePath
:
''
}
},
onLoad
()
{
let
self
=
this
;
recorderManager
.
onStop
(
function
(
res
)
{
console
.
log
(
'
recorder stop
'
+
JSON
.
stringify
(
res
));
self
.
voicePath
=
res
.
tempFilePath
;
});
},
methods
:
{
startRecord
()
{
console
.
log
(
'
开始录音
'
);
recorderManager
.
start
();
},
endRecord
()
{
console
.
log
(
'
录音结束
'
);
recorderManager
.
stop
();
},
playVoice
()
{
console
.
log
(
'
播放录音
'
);
if
(
this
.
voicePath
)
{
innerAudioContext
.
src
=
this
.
voicePath
;
innerAudioContext
.
play
();
}
}
}
}
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录