@@ -21,7 +21,7 @@ This following figure shows the audio capturer state transitions.
...
@@ -21,7 +21,7 @@ This following figure shows the audio capturer state transitions.
## Constraints
## Constraints
Before developing the audio data collection feature, configure the **ohos.permission.MICROPHONE** permission for your application. For details about permission configuration, see [Permission Application Guide](../security/accesstoken-guidelines.md).
Before developing the audio data collection feature, configure the **ohos.permission.MICROPHONE** permission for your application. For details, see [Permission Application Guide](../security/accesstoken-guidelines.md).
## How to Develop
## How to Develop
...
@@ -72,7 +72,7 @@ For details about the APIs, see [AudioCapturer in Audio Management](../reference
...
@@ -72,7 +72,7 @@ For details about the APIs, see [AudioCapturer in Audio Management](../reference
}
}
awaitaudioCapturer.start();
awaitaudioCapturer.start();
letstate=audioCapturer.state;
state=audioCapturer.state;
if(state==audio.AudioState.STATE_RUNNING){
if(state==audio.AudioState.STATE_RUNNING){
console.info('AudioRecLog: Capturer started');
console.info('AudioRecLog: Capturer started');
}else{
}else{
...
@@ -86,7 +86,7 @@ For details about the APIs, see [AudioCapturer in Audio Management](../reference
...
@@ -86,7 +86,7 @@ For details about the APIs, see [AudioCapturer in Audio Management](../reference
The following example shows how to write recorded data into a file.
The following example shows how to write recorded data into a file.
```js
```js
importfileiofrom'@ohos.fileio';
importfsfrom'@ohos.file.fs';
letstate=audioCapturer.state;
letstate=audioCapturer.state;
// The read operation can be performed only when the state is STATE_RUNNING.
// The read operation can be performed only when the state is STATE_RUNNING.
...
@@ -96,31 +96,36 @@ For details about the APIs, see [AudioCapturer in Audio Management](../reference
...
@@ -96,31 +96,36 @@ For details about the APIs, see [AudioCapturer in Audio Management](../reference
}
}
constpath='/data/data/.pulse_dir/capture_js.wav';// Path for storing the collected audio file.
constpath='/data/data/.pulse_dir/capture_js.wav';// Path for storing the collected audio file.
@@ -33,10 +33,9 @@ The following figure shows the audio renderer state transitions.
...
@@ -33,10 +33,9 @@ The following figure shows the audio renderer state transitions.
For details about the APIs, see [AudioRenderer in Audio Management](../reference/apis/js-apis-audio.md#audiorenderer8).
For details about the APIs, see [AudioRenderer in Audio Management](../reference/apis/js-apis-audio.md#audiorenderer8).
1. Use **createAudioRenderer()** to create an **AudioRenderer** instance.
1. Use **createAudioRenderer()** to create an **AudioRenderer** instance.
Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. This instance is used to render audio, control and obtain the rendering status, and register a callback for notification.
Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. This instance is used to render audio, control and obtain the rendering status, and register a callback for notification.
```js
```js
importaudiofrom'@ohos.multimedia.audio';
importaudiofrom'@ohos.multimedia.audio';
...
@@ -59,7 +58,7 @@ Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. Th
...
@@ -59,7 +58,7 @@ Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. Th
letdir=globalThis.fileDir;// You must use the sandbox path.
letdir=globalThis.fileDir;// You must use the sandbox path.
constpath=dir+'/file_example_WAV_2MG.wav';// The file to render is in the following path: /data/storage/el2/base/haps/entry/files/file_example_WAV_2MG.wav
constfilePath=dir+'/file_example_WAV_2MG.wav';// The file to render is in the following path: /data/storage/el2/base/haps/entry/files/file_example_WAV_2MG.wav
console.info(`file path: ${path}`);
console.info(`file filePath: ${filePath}`);
letss=fileio.createStreamSync(path,'r');
consttotalSize=fileio.statSync(path).size;// Size of the file to render.
@@ -424,35 +421,31 @@ Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. Th
...
@@ -424,35 +421,31 @@ Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. Th
letdir=globalThis.fileDir;// You must use the sandbox path.
letdir=globalThis.fileDir;// You must use the sandbox path.
constpath1=dir+'/music001_48000_32_1.wav';// The file to render is in the following path: /data/storage/el2/base/haps/entry/files/music001_48000_32_1.wav
constpath1=dir+'/music001_48000_32_1.wav';// The file to render is in the following path: /data/storage/el2/base/haps/entry/files/music001_48000_32_1.wav
@@ -499,36 +492,32 @@ Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. Th
...
@@ -499,36 +492,32 @@ Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. Th
// 2.6 Read the original audio data file.
// 2.6 Read the original audio data file.
letdir=globalThis.fileDir;// You must use the sandbox path.
letdir=globalThis.fileDir;// You must use the sandbox path.
constpath2=dir+'/music002_48000_32_1.wav';// The file to render is in the following path: /data/storage/el2/base/haps/entry/files/music002_48000_32_1.wav
constpath2=dir+'/music002_48000_32_1.wav';// The file to render is in the following path: /data/storage/el2/base/haps/entry/files/music002_48000_32_1.wav