Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
a416eea8
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
a416eea8
编写于
8月 23, 2022
作者:
三
三三四四
提交者:
Gitee
8月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update zh-cn/application-dev/media/audio-capturer.md.
修改缩进样式 Signed-off-by:
N
三三四四
<
1184956293@qq.com
>
上级
bcf0265d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
53 addition
and
53 deletion
+53
-53
zh-cn/application-dev/media/audio-capturer.md
zh-cn/application-dev/media/audio-capturer.md
+53
-53
未找到文件。
zh-cn/application-dev/media/audio-capturer.md
浏览文件 @
a416eea8
...
@@ -22,24 +22,24 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
...
@@ -22,24 +22,24 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
```
js
```
js
var
audioStreamInfo
=
{
var
audioStreamInfo
=
{
samplingRate
:
audio
.
AudioSamplingRate
.
SAMPLE_RATE_44100
,
samplingRate
:
audio
.
AudioSamplingRate
.
SAMPLE_RATE_44100
,
channels
:
audio
.
AudioChannel
.
CHANNEL_1
,
channels
:
audio
.
AudioChannel
.
CHANNEL_1
,
sampleFormat
:
audio
.
AudioSampleFormat
.
SAMPLE_FORMAT_S16LE
,
sampleFormat
:
audio
.
AudioSampleFormat
.
SAMPLE_FORMAT_S16LE
,
encodingType
:
audio
.
AudioEncodingType
.
ENCODING_TYPE_RAW
encodingType
:
audio
.
AudioEncodingType
.
ENCODING_TYPE_RAW
}
}
var
audioCapturerInfo
=
{
var
audioCapturerInfo
=
{
source
:
audio
.
SourceType
.
SOURCE_TYPE_MIC
,
source
:
audio
.
SourceType
.
SOURCE_TYPE_MIC
,
capturerFlags
:
1
capturerFlags
:
1
}
}
var
audioCapturerOptions
=
{
var
audioCapturerOptions
=
{
streamInfo
:
audioStreamInfo
,
streamInfo
:
audioStreamInfo
,
capturerInfo
:
audioCapturerInfo
capturerInfo
:
audioCapturerInfo
}
}
let
audioCapturer
=
await
audio
.
createAudioCapturer
(
audioCapturerOptions
);
let
audioCapturer
=
await
audio
.
createAudioCapturer
(
audioCapturerOptions
);
var
state
=
audioRenderer
.
state
;
var
state
=
audioRenderer
.
state
;
```
```
2.
(可选)使用on('stateChange')订阅音频采集器状态更改。
2.
(可选)使用on('stateChange')订阅音频采集器状态更改。
...
@@ -49,26 +49,26 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
...
@@ -49,26 +49,26 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
audioCapturer
.
on
(
'
stateChange
'
,(
state
)
=>
{
audioCapturer
.
on
(
'
stateChange
'
,(
state
)
=>
{
console
.
info
(
'
AudioCapturerLog: Changed State to :
'
+
state
)
console
.
info
(
'
AudioCapturerLog: Changed State to :
'
+
state
)
switch
(
state
)
{
switch
(
state
)
{
case
audio
.
AudioState
.
STATE_PREPARED
:
case
audio
.
AudioState
.
STATE_PREPARED
:
console
.
info
(
'
--------CHANGE IN AUDIO STATE----------PREPARED--------------
'
);
console
.
info
(
'
--------CHANGE IN AUDIO STATE----------PREPARED--------------
'
);
console
.
info
(
'
Audio State is : Prepared
'
);
console
.
info
(
'
Audio State is : Prepared
'
);
break
;
break
;
case
audio
.
AudioState
.
STATE_RUNNING
:
case
audio
.
AudioState
.
STATE_RUNNING
:
console
.
info
(
'
--------CHANGE IN AUDIO STATE----------RUNNING--------------
'
);
console
.
info
(
'
--------CHANGE IN AUDIO STATE----------RUNNING--------------
'
);
console
.
info
(
'
Audio State is : Running
'
);
console
.
info
(
'
Audio State is : Running
'
);
break
;
break
;
case
audio
.
AudioState
.
STATE_STOPPED
:
case
audio
.
AudioState
.
STATE_STOPPED
:
console
.
info
(
'
--------CHANGE IN AUDIO STATE----------STOPPED--------------
'
);
console
.
info
(
'
--------CHANGE IN AUDIO STATE----------STOPPED--------------
'
);
console
.
info
(
'
Audio State is : stopped
'
);
console
.
info
(
'
Audio State is : stopped
'
);
break
;
break
;
case
audio
.
AudioState
.
STATE_RELEASED
:
case
audio
.
AudioState
.
STATE_RELEASED
:
console
.
info
(
'
--------CHANGE IN AUDIO STATE----------RELEASED--------------
'
);
console
.
info
(
'
--------CHANGE IN AUDIO STATE----------RELEASED--------------
'
);
console
.
info
(
'
Audio State is : released
'
);
console
.
info
(
'
Audio State is : released
'
);
break
;
break
;
default
:
default
:
console
.
info
(
'
--------CHANGE IN AUDIO STATE----------INVALID--------------
'
);
console
.
info
(
'
--------CHANGE IN AUDIO STATE----------INVALID--------------
'
);
console
.
info
(
'
Audio State is : invalid
'
);
console
.
info
(
'
Audio State is : invalid
'
);
break
;
break
;
}
}
});
});
```
```
...
@@ -80,9 +80,9 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
...
@@ -80,9 +80,9 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
```
js
```
js
await
audioCapturer
.
start
();
await
audioCapturer
.
start
();
if
(
audioCapturer
.
state
==
audio
.
AudioState
.
STATE_RUNNING
)
{
if
(
audioCapturer
.
state
==
audio
.
AudioState
.
STATE_RUNNING
)
{
console
.
info
(
'
AudioRecLog: Capturer started
'
);
console
.
info
(
'
AudioRecLog: Capturer started
'
);
}
else
{
}
else
{
console
.
info
(
'
AudioRecLog: Capturer start failed
'
);
console
.
info
(
'
AudioRecLog: Capturer start failed
'
);
}
}
```
```
...
@@ -103,29 +103,29 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
...
@@ -103,29 +103,29 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
const
path
=
'
/data/data/.pulse_dir/capture_js.wav
'
;
const
path
=
'
/data/data/.pulse_dir/capture_js.wav
'
;
let
fd
=
fileio
.
openSync
(
path
,
0o102
,
0o777
);
let
fd
=
fileio
.
openSync
(
path
,
0o102
,
0o777
);
if
(
fd
!==
null
)
{
if
(
fd
!==
null
)
{
console
.
info
(
'
AudioRecLog: file fd created
'
);
console
.
info
(
'
AudioRecLog: file fd created
'
);
}
}
else
{
else
{
console
.
info
(
'
AudioRecLog: file fd create : FAILED
'
);
console
.
info
(
'
AudioRecLog: file fd create : FAILED
'
);
return
;
return
;
}
}
fd
=
fileio
.
openSync
(
path
,
0o2002
,
0o666
);
fd
=
fileio
.
openSync
(
path
,
0o2002
,
0o666
);
if
(
fd
!==
null
)
{
if
(
fd
!==
null
)
{
console
.
info
(
'
AudioRecLog: file fd opened in append mode
'
);
console
.
info
(
'
AudioRecLog: file fd opened in append mode
'
);
}
}
var
numBuffersToCapture
=
150
;
var
numBuffersToCapture
=
150
;
while
(
numBuffersToCapture
)
{
while
(
numBuffersToCapture
)
{
var
buffer
=
await
audioCapturer
.
read
(
bufferSize
,
true
);
var
buffer
=
await
audioCapturer
.
read
(
bufferSize
,
true
);
if
(
typeof
(
buffer
)
==
undefined
)
{
if
(
typeof
(
buffer
)
==
undefined
)
{
console
.
info
(
'
read buffer failed
'
);
console
.
info
(
'
read buffer failed
'
);
}
else
{
}
else
{
var
number
=
fileio
.
writeSync
(
fd
,
buffer
);
var
number
=
fileio
.
writeSync
(
fd
,
buffer
);
console
.
info
(
'
AudioRecLog: data written:
'
+
number
);
console
.
info
(
'
AudioRecLog: data written:
'
+
number
);
}
}
numBuffersToCapture
--
;
numBuffersToCapture
--
;
}
}
```
```
...
@@ -134,9 +134,9 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
...
@@ -134,9 +134,9 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
```
```
await audioCapturer.stop();
await audioCapturer.stop();
if (audioCapturer.state == audio.AudioState.STATE_STOPPED) {
if (audioCapturer.state == audio.AudioState.STATE_STOPPED) {
console.info('AudioRecLog: Capturer stopped');
console.info('AudioRecLog: Capturer stopped');
} else {
} else {
console.info('AudioRecLog: Capturer stop failed');
console.info('AudioRecLog: Capturer stop failed');
}
}
```
```
...
@@ -145,8 +145,8 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
...
@@ -145,8 +145,8 @@ AudioCapturer提供了用于获取原始音频文件的方法。开发者可以
```
js
```
js
await
audioCapturer
.
release
();
await
audioCapturer
.
release
();
if
(
audioCapturer
.
state
==
audio
.
AudioState
.
STATE_RELEASED
)
{
if
(
audioCapturer
.
state
==
audio
.
AudioState
.
STATE_RELEASED
)
{
console
.
info
(
'
AudioRecLog: Capturer released
'
);
console
.
info
(
'
AudioRecLog: Capturer released
'
);
}
else
{
}
else
{
console
.
info
(
'
AudioRecLog: Capturer release failed
'
);
console
.
info
(
'
AudioRecLog: Capturer release failed
'
);
}
}
```
```
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录