diff --git a/zh-cn/application-dev/media/audio-effect-management.md b/zh-cn/application-dev/media/audio-effect-management.md
index 414fb2aa9f7936a9ef8bedbb2698fd1bb0879f61..1f28fa95e80e1336a3e7550890aba9639043d7e0 100644
--- a/zh-cn/application-dev/media/audio-effect-management.md
+++ b/zh-cn/application-dev/media/audio-effect-management.md
@@ -6,52 +6,55 @@
主要包括查询和设置当前音频播放流的音效模式,音效模式包括EFFECT_NONE关闭音效模式和EFFECT_DEFAULT默认音效模式。默认音效模式会根据创建音频流的ContentType和StreamUsage自动加载对应场景的音效。
-### 获取播放实例(示例代码仅支持JS格式)
+### 获取播放实例
管理播放实例音效的接口是getAudioEffectMode()查询当前音频播放流的音效模式和setAudioEffectMode(mode: AudioEffectMode)设置当前音频播放流的音效模式,在使用之前,需要使用createAudioRenderer(options: AudioRendererOptions)先创建音频播放流AudioRenderer实例。
1. 步骤一:导入音频接口。
- ```js
+ ```ts
import audio from '@ohos.multimedia.audio';
```
2. 步骤二:配置音频渲染参数并创建AudioRenderer实例,音频渲染参数的详细信息可以查看[AudioRendererOptions](../reference/apis/js-apis-audio.md#audiorendereroptions8),创建AudioRenderer实例时会默认挂载EFFECT_DEFAULT模式音效。
- ```js
- let audioStreamInfo = {
+ ```ts
+ import audio from '@ohos.multimedia.audio';
+ import { BusinessError } from '@ohos.base';
+ let audioStreamInfo: audio.AudioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
channels: audio.AudioChannel.CHANNEL_1,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
};
- let audioRendererInfo = {
+ let audioRendererInfo: audio.AudioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 0
};
- let audioRendererOptions = {
+ let audioRendererOptions: audio.AudioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
};
- audio.createAudioRenderer(audioRendererOptions, (err, data) => {
+ audio.createAudioRenderer(audioRendererOptions, (err: BusinessError, data: audio.AudioRenderer) => {
if (err) {
console.error(`Invoke createAudioRenderer failed, code is ${err.code}, message is ${err.message}`);
return;
} else {
console.info('Invoke createAudioRenderer succeeded.');
- let audioRenderer = data;
+ let audioRenderer: audio.AudioRenderer = data;
}
});
```
-### 查询当前播放实例的音效模式(示例代码仅支持JS格式)
+### 查询当前播放实例的音效模式
- ```js
- audioRenderer.getAudioEffectMode((err, effectmode) => {
+ ```ts
+ import { BusinessError } from '@ohos.base';
+ audioRenderer.getAudioEffectMode((err: BusinessError, effectmode: audio.AudioEffectMode) => {
if (err) {
console.error(`Failed to get params, code is ${err.code}, message is ${err.message}`);
return;
@@ -61,12 +64,13 @@
});
```
-### 设置当前播放实例的音效模式(示例代码仅支持JS格式)
+### 设置当前播放实例的音效模式
关闭系统音效:
- ```js
- audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_NONE, (err) => {
+ ```ts
+ import { BusinessError } from '@ohos.base';
+ audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_NONE, (err: BusinessError) => {
if (err) {
console.error(`Failed to set params, code is ${err.code}, message is ${err.message}`);
return;
@@ -78,8 +82,9 @@
开启系统音效默认模式:
- ```js
- audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT, (err) => {
+ ```ts
+ import { BusinessError } from '@ohos.base';
+ audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT, (err: BusinessError) => {
if (err) {
console.error(`Failed to set params, code is ${err.code}, message is ${err.message}`);
return;
@@ -94,20 +99,21 @@
主要包括全局音效查询相应StreamUsage对应场景的音效模式。
对于播放音频类的应用,开发者需要关注该应用的音频流使用什么音效模式并做出相应的操作,比如音乐App播放时,应选择音乐场景下的模式。在使用查询接口前,开发者需要使用getStreamManager()创建一个AudioStreamManager音频流管理实例。
-### 获取音频流管理接口(示例代码仅支持JS格式)
+### 获取音频流管理接口
1.创建AudioStreamManager实例。在使用AudioStreamManager的API前,需要使用getStreamManager()创建一个AudioStreamManager实例。
- ```js
+ ```ts
import audio from '@ohos.multimedia.audio';
let audioManager = audio.getAudioManager();
let audioStreamManager = audioManager.getStreamManager();
```
-### 查询对应场景的音效模式(示例代码仅支持JS格式)
+### 查询对应场景的音效模式
- ```js
- audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MEDIA, async (err, audioEffectInfoArray) => {
+ ```ts
+ import { BusinessError } from '@ohos.base';
+ audioStreamManager.getAudioEffectInfoArray(audio.StreamUsage.STREAM_USAGE_MEDIA, async (err: BusinessError, audioEffectInfoArray: audio.AudioEffectInfoArray) => {
if (err) {
console.error('Failed to get effect info array');
return;
diff --git a/zh-cn/application-dev/reference/apis/js-apis-audio.md b/zh-cn/application-dev/reference/apis/js-apis-audio.md
index 02f15a7181622a67d90ec77b3717321fd62f994a..306dd828a3d59c50ac6100c3faf9685455c084c9 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-audio.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-audio.md
@@ -14,7 +14,7 @@
## 导入模块
-```js
+```ts
import audio from '@ohos.multimedia.audio';
```
@@ -28,7 +28,7 @@ import audio from '@ohos.multimedia.audio';
**示例:**
-```js
+```ts
import audio from '@ohos.multimedia.audio';
const localNetworkId = audio.LOCAL_NETWORK_ID;
@@ -51,8 +51,8 @@ getAudioManager(): AudioManager
| [AudioManager](#audiomanager) | 音频管理类。 |
**示例:**
-```js
-let audioManager = audio.getAudioManager();
+```ts
+let audioManager: audio.AudioManager = audio.getAudioManager();
```
## audio.createAudioRenderer8+
@@ -72,24 +72,24 @@ createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\
**示例:**
-```js
+```ts
import fs from '@ohos.file.fs';
import audio from '@ohos.multimedia.audio';
+import { BusinessError } from '@ohos.base';
-let audioStreamInfo = {
+let audioStreamInfo: audio.AudioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
channels: audio.AudioChannel.CHANNEL_1,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
-let audioRendererInfo = {
+let audioRendererInfo: audio.AudioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 0
}
-let audioRendererOptions = {
+let audioRendererOptions: audio.AudioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
}
-let audioRenderer;
+let audioRenderer: audio.AudioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
audioRenderer = data;
console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS');
-}).catch((err) => {
+}).catch((err: BusinessError) => {
console.error(`AudioFrameworkRenderLog: AudioRenderer Created : ERROR : ${err}`);
});
```
@@ -176,21 +177,21 @@ createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback