@@ -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.
@@ -34,8 +34,7 @@ For details about the APIs, see [AudioRenderer in Audio Management](../reference
...
@@ -34,8 +34,7 @@ For details about the APIs, see [AudioRenderer in Audio Management](../reference
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';
...
@@ -82,15 +81,15 @@ Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. Th
...
@@ -82,15 +81,15 @@ Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. Th
}
}
}
}
```
```
The renderer state will be **STATE_RUNNING** once the audio renderer is started. The application can then begin reading buffers.
The renderer state will be **STATE_RUNNING** once the audio renderer is started. The application can then begin reading buffers.
3. Call **write()** to write data to the buffer.
3. Call **write()** to write data to the buffer.
Read the audio data to be played to the buffer. Call **write()** repeatedly to write the data to the buffer.
Read the audio data to be played to the buffer. Call **write()** repeatedly to write the data to the buffer.
```js
```js
importfileiofrom'@ohos.fileio';
importfsfrom'@ohos.file.fs';
importaudiofrom'@ohos.multimedia.audio';
importaudiofrom'@ohos.multimedia.audio';
asyncfunctionwriteBuffer(buf){
asyncfunctionwriteBuffer(buf){
...
@@ -109,35 +108,33 @@ Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. Th
...
@@ -109,35 +108,33 @@ Set parameters of the **AudioRenderer** instance in **audioRendererOptions**. Th
// Set a proper buffer size for the audio renderer. You can also select a buffer of another size.
// Set a proper buffer size for the audio renderer. You can also select a buffer of another size.
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