• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimedia.audio (音频管理)(系统接口)
2
3音频管理提供管理音频的一些基础能力,包括对音频音量、音频设备的管理,以及对音频数据的采集和渲染等。
4
5该模块提供以下音频相关的常用功能:
6
7- [AudioManager](#audiomanager):音频管理。
8- [TonePlayer](#toneplayer9):用于管理和播放DTMF(Dual Tone Multi Frequency,双音多频)音调,如拨号音、通话回铃音等。
9
10> **说明:**
11>
12> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
13> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.multimedia.audio (音频管理)](js-apis-audio.md)。
14
15## 导入模块
16
17```ts
18import { audio } from '@kit.AudioKit';
19```
20
21## 常量
22
23| 名称                                    | 类型      | 可读  | 可写 | 说明               |
24| --------------------------------------- | ----------| ---- | ---- | ------------------ |
25| LOCAL_NETWORK_ID<sup>9+</sup>           | string    | 是   | 否   | 本地设备网络id。<br/>此接口为系统接口。<br> **系统能力:** SystemCapability.Multimedia.Audio.Device  |
26
27## audio.createTonePlayer<sup>9+</sup>
28
29createTonePlayer(options: AudioRendererInfo, callback: AsyncCallback&lt;TonePlayer&gt;): void
30
31创建DTMF播放器。使用callback方式异步返回结果。
32
33**系统能力:** SystemCapability.Multimedia.Audio.Tone
34
35**系统接口:** 该接口为系统接口
36
37**参数:**
38
39| 参数名   | 类型                                             | 必填 | 说明            |
40| -------- | ----------------------------------------------- | ---- | -------------- |
41| options  | [AudioRendererInfo](js-apis-audio.md#audiorendererinfo8)        | 是   | 配置音频渲染器信息。|
42| callback | AsyncCallback<[TonePlayer](#toneplayer9)>       | 是   | 回调函数。当获取DTMF播放器成功,err为undefined,data为获取到的DTMF播放器对象;否则为错误对象。|
43
44**示例:**
45
46```ts
47import { audio } from '@kit.AudioKit';
48
49let audioRendererInfo: audio.AudioRendererInfo = {
50  usage : audio.StreamUsage.STREAM_USAGE_DTMF,
51  rendererFlags : 0
52};
53let tonePlayer: audio.TonePlayer;
54
55audio.createTonePlayer(audioRendererInfo, (err, data) => {
56  console.info(`callback call createTonePlayer: audioRendererInfo: ${audioRendererInfo}`);
57  if (err) {
58    console.error(`callback call createTonePlayer return error: ${err.message}`);
59  } else {
60    console.info(`callback call createTonePlayer return data: ${data}`);
61    tonePlayer = data;
62  }
63});
64```
65
66## audio.createTonePlayer<sup>9+</sup>
67
68createTonePlayer(options: AudioRendererInfo): Promise&lt;TonePlayer&gt;
69
70创建DTMF播放器。使用Promise方式异步返回结果。
71
72**系统能力:** SystemCapability.Multimedia.Audio.Tone
73
74**系统接口:** 该接口为系统接口
75
76**参数:**
77
78| 参数名  | 类型                                           | 必填 | 说明         |
79| :------ | :---------------------------------------------| :--- | :----------- |
80| options | [AudioRendererInfo](js-apis-audio.md#audiorendererinfo8)      | 是   | 配置音频渲染器信息。 |
81
82**返回值:**
83
84| 类型                                      | 说明                             |
85| ----------------------------------------- | -------------------------------- |
86| Promise<[TonePlayer](#toneplayer9)>       | Promise对象,返回DTMF播放器对象。 |
87
88**示例:**
89
90```ts
91import { audio } from '@kit.AudioKit';
92
93let tonePlayer: audio.TonePlayer;
94async function createTonePlayerBefore(){
95  let audioRendererInfo: audio.AudioRendererInfo = {
96    usage : audio.StreamUsage.STREAM_USAGE_DTMF,
97    rendererFlags : 0
98  };
99  tonePlayer = await audio.createTonePlayer(audioRendererInfo);
100}
101```
102
103## audio.createAsrProcessingController<sup>12+</sup>
104
105createAsrProcessingController(audioCapturer: AudioCapturer): AsrProcessingController;
106
107获取ASR处理控制器
108
109**系统接口:** 该接口为系统接口
110
111**系统能力:** SystemCapability.Multimedia.Audio.Capturer
112
113**返回值:**
114
115| 类型                                                    | 说明         |
116|-------------------------------------------------------| ------------ |
117| [AsrProcessingController](#asrprocessingcontroller12) | ASR处理控制器对象。 |
118
119**错误码:**
120
121以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
122
123| 错误码ID   | 错误信息                                     |
124|---------|------------------------------------------|
125| 202 | Caller is not a system application. |
126| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
127| 6800101 | Parameter verification failed. |
128| 6800104 | Operation not allowed. |
129
130**示例:**
131
132```ts
133import { audio } from '@kit.AudioKit';
134
135let audioStreamInfo: audio.AudioStreamInfo = {
136  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
137  channels: audio.AudioChannel.CHANNEL_2,
138  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
139  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
140};
141
142let audioCapturerInfo: audio.AudioCapturerInfo = {
143  source: audio.SourceType.SOURCE_TYPE_MIC,
144  capturerFlags: 0
145};
146
147let audioCapturerOptions: audio.AudioCapturerOptions = {
148  streamInfo: audioStreamInfo,
149  capturerInfo: audioCapturerInfo
150};
151
152audio.createAudioCapturer(audioCapturerOptions, (err, data) => {
153  if (err) {
154    console.error(`AudioCapturer Created : Error: ${err}`);
155  } else {
156    console.info('AudioCapturer Created : Success : SUCCESS');
157    let audioCapturer = data;
158    let asrProcessingController = audio.createAsrProcessingController(audioCapturer);
159    console.info('AsrProcessingController Created : Success : SUCCESS');
160  }
161});
162```
163
164## AudioVolumeType
165
166枚举,音频流类型。
167
168**系统能力:** SystemCapability.Multimedia.Audio.Volume
169
170| 名称                         | 值      | 说明       |
171| ---------------------------- | ------ | ---------- |
172| ULTRASONIC<sup>10+</sup>     | 10     | 超声波。<br/>此接口为系统接口。|
173| ALL<sup>9+</sup>             | 100    | 所有公共音频流。<br/>此接口为系统接口。|
174
175## InterruptRequestResultType<sup>9+</sup>
176
177枚举,音频中断请求结果类型。
178
179**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
180
181**系统接口:** 该接口为系统接口
182
183| 名称                         | 值      | 说明       |
184| ---------------------------- | ------ | ---------- |
185| INTERRUPT_REQUEST_GRANT      | 0      | 请求音频中断成功。 |
186| INTERRUPT_REQUEST_REJECT     | 1      | 请求音频中断失败,可能具有较高优先级类型。 |
187
188## DeviceFlag
189
190枚举,可获取的设备种类。
191
192**系统能力:** SystemCapability.Multimedia.Audio.Device
193
194| 名称                            |  值     | 说明                        |
195| ------------------------------- | ------ |---------------------------|
196| NONE_DEVICES_FLAG<sup>9+</sup>  | 0      | 无设备。 <br/>此接口为系统接口。        |
197| DISTRIBUTED_OUTPUT_DEVICES_FLAG<sup>9+</sup> | 4   | 分布式输出设备。<br/>此接口为系统接口。    |
198| DISTRIBUTED_INPUT_DEVICES_FLAG<sup>9+</sup>  | 8   | 分布式输入设备。<br/>此接口为系统接口。    |
199| ALL_DISTRIBUTED_DEVICES_FLAG<sup>9+</sup>    | 12  | 分布式输入和输出设备。<br/>此接口为系统接口。 |
200
201## EffectFlag<sup>18+</sup>
202
203枚举,音效分类。
204
205**系统接口:** 该接口为系统接口
206
207**系统能力:** SystemCapability.Multimedia.Audio.Core
208
209| 名称                            |  值     | 说明                        |
210| ------------------------------- | ------ |------------------------------|
211| RENDER_EFFECT_FLAG  | 0      | 下行音效类型。   |
212| CAPTURE_EFFECT_FLAG | 1      | 上行音效类型。   |
213
214## AudioEffectProperty<sup>18+</sup>
215
216音效属性。
217
218**系统接口:** 该接口为系统接口
219
220**系统能力:** SystemCapability.Multimedia.Audio.Core
221
222| 名称               | 类型 | 必填 | 说明       |
223| ------------------ | ---- | ---- | --------- |
224| name         | string | 是 | 音效名称。 |
225| category     | string | 是 | 音效分类。 |
226| flag        | [EffectFlag](#effectflag18) | 是 | 音效分类。 |
227
228## StreamUsage
229
230枚举,音频流使用类型。
231
232**系统能力:** SystemCapability.Multimedia.Audio.Core
233
234| 名称                                      |  值    | 说明                                                                                                                                          |
235| ------------------------------------------| ------ |---------------------------------------------------------------------------------------------------------------------------------------------|
236| STREAM_USAGE_SYSTEM<sup>10+</sup>         | 9      | 系统音(如屏幕锁定或按键音)。<br/>此接口为系统接口。  |
237| STREAM_USAGE_DTMF<sup>10+</sup>           | 14     | 拨号音。<br/>此接口为系统接口。    |
238| STREAM_USAGE_ENFORCED_TONE<sup>10+</sup>  | 15     | 强制音(如相机快门音)。<br/>此接口为系统接口。   |
239| STREAM_USAGE_ULTRASONIC<sup>10+</sup>     | 16     | 超声波(目前仅提供给MSDP使用)。<br/>此接口为系统接口。 |
240| STREAM_USAGE_VOICE_CALL_ASSISTANT<sup>12+</sup>     | 21     | 通话辅助语音。<br/>此接口为系统接口。 |
241
242## InterruptRequestType<sup>9+</sup>
243
244枚举,音频中断请求类型。
245
246**系统接口:** 该接口为系统接口
247
248**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
249
250| 名称                               |  值     | 说明                       |
251| ---------------------------------- | ------ | ------------------------- |
252| INTERRUPT_REQUEST_TYPE_DEFAULT     | 0      |  默认类型,可中断音频请求。  |
253
254## VolumeFlag<sup>12+</sup>
255
256枚举,音量相关操作。
257
258**系统接口:** 该接口为系统接口
259
260**系统能力:** SystemCapability.Multimedia.Audio.Volume
261
262| 名称                               | 值 | 说明       |
263| ---------------------------------- |---|----------|
264| FLAG_SHOW_SYSTEM_UI | 1 | 拉起系统音量条。 |
265
266## AsrNoiseSuppressionMode<sup>12+</sup>
267
268枚举,ASR 噪音抑制模式
269
270**系统接口:** 该接口为系统接口
271
272**系统能力:** SystemCapability.Multimedia.Audio.Capturer
273
274| 名称|  值 | 说明 |
275|-------|-------|-------|
276| BYPASS | 0 |旁路噪音抑制|
277| STANDARD | 1 |标准噪音抑制|
278| NEAR_FIELD | 2 |近场噪音抑制|
279| FAR_FIELD | 3 |远场噪音抑制|
280
281## AsrAecMode<sup>12+</sup>
282
283枚举,ASR AEC 模式
284
285**系统接口:** 该接口为系统接口
286
287**系统能力:** SystemCapability.Multimedia.Audio.Capturer
288
289| 名称|  值 | 说明 |
290|-------|-------|-------|
291| BYPASS | 0 |BYPASS AEC|
292| STANDARD | 1 |STANDARD AEC|
293
294## AsrWhisperDetectionMode<sup>12+</sup>
295
296枚举,ASR(Automatic Speech Recognition,自动语音识别)耳语检测模式。
297
298**系统接口:** 该接口为系统接口
299
300**系统能力:** SystemCapability.Multimedia.Audio.Capturer
301
302| 名称  | 值 | 说明       |
303|-----|---|----------|
304| BYPASS  | 0 | 不启用检测模型。 |
305| STANDARD | 1 | 耳语检测模型。  |
306
307## AsrVoiceControlMode<sup>12+</sup>
308
309枚举,ASR音频通路模式。
310
311**系统接口:** 该接口为系统接口
312
313**系统能力:** SystemCapability.Multimedia.Audio.Capturer
314
315| 名称                      | 值 | 说明                                    |
316|-------------------------|---|---------------------------------------|
317| AUDIO_2_VOICE_TX        | 0 | 仅媒体音频流生效。                            |
318| AUDIO_MIX_2_VOICE_TX    | 1 | 媒体音频流和MIC音频流均生效。                      |
319| AUDIO_2_VOICE_TX_EX     | 2 | 仅媒体音频流生效,将媒体流上报给通话录音。     |
320| AUDIO_MIX_2_VOICE_TX_EX | 3 | 媒体音频流和MIC音频流均生效,将媒体流上报给通话录音。 |
321
322## AsrVoiceMuteMode<sup>12+</sup>
323
324枚举,ASR静音模式。
325
326**系统接口:** 该接口为系统接口
327
328**系统能力:** SystemCapability.Multimedia.Audio.Capturer
329
330| 名称             | 值 | 说明                  |
331|----------------|---|---------------------|
332| OUTPUT_MUTE    | 0 | 本地输出静音。            |
333| INPUT_MUTE     | 1 | 本地的MIC输入静音。        |
334| TTS_MUTE       | 2 | 应用下发的媒体音频本地静音。     |
335| CALL_MUTE      | 3 | 通话语音流静音。          |
336| OUTPUT_MUTE_EX | 4 | 本地输出静音,媒体音频流送给通话录音。 |
337
338## InterruptResult<sup>9+</sup>
339
340音频中断结果。
341
342**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
343
344**系统接口:** 该接口为系统接口
345
346| 名称          | 类型                                                            | 必填 | 说明             |
347| --------------| -------------------------------------------------------------- | ---- | ---------------- |
348| requestResult | [InterruptRequestResultType](#interruptrequestresulttype9)     | 是   | 表示音频请求中断类型。 |
349| interruptNode | number                                                         | 是   | 音频请求中断的节点。 |
350
351## VolumeEvent<sup>9+</sup>
352
353音量改变时,应用接收的事件。
354
355**系统能力:** SystemCapability.Multimedia.Audio.Volume
356
357| 名称       | 类型                                | 必填   | 说明                                        |
358| ---------- | ----------------------------------- | ---- |-------------------------------------------|
359| volumeGroupId | number                           | 是   | 音量组id,可用于getGroupManager入参。<br/>此接口为系统接口。 |
360| networkId  | string                              | 是   | 网络id。<br/>此接口为系统接口。    |
361
362## ConnectType<sup>9+</sup>
363
364枚举,设备连接类型。
365
366**系统接口:** 该接口为系统接口
367
368**系统能力:** SystemCapability.Multimedia.Audio.Volume
369
370| 名称                            |  值     | 说明                   |
371| :------------------------------ | :----- | :--------------------- |
372| CONNECT_TYPE_LOCAL              | 1      | 本地设备。         |
373| CONNECT_TYPE_DISTRIBUTED        | 2      | 分布式设备。            |
374
375## VolumeGroupInfos<sup>9+</sup>
376
377音量组信息,数组类型,为[VolumeGroupInfo](#volumegroupinfo9)的数组,只读。
378
379**系统接口:** 该接口为系统接口
380
381**系统能力:** SystemCapability.Multimedia.Audio.Volume
382
383## VolumeGroupInfo<sup>9+</sup>
384
385音量组信息。
386
387**系统接口:** 该接口为系统接口
388
389**系统能力:** SystemCapability.Multimedia.Audio.Volume
390
391| 名称                        | 类型                       | 可读 | 可写 | 说明       |
392| -------------------------- | -------------------------- | ---- | ---- | ---------- |
393| networkId<sup>9+</sup>     | string                     | 是   | 否   | 组网络id。  |
394| groupId<sup>9+</sup>       | number                     | 是   | 否   | 组设备组id。 |
395| mappingId<sup>9+</sup>     | number                     | 是   | 否   | 组映射id。 |
396| groupName<sup>9+</sup>     | string                     | 是   | 否   | 组名。 |
397| type<sup>9+</sup>          | [ConnectType](#connecttype9)| 是   | 否   | 连接设备类型。 |
398
399## SourceType<sup>8+</sup>
400
401枚举,音源类型。
402
403| 名称                                         |  值     | 说明                   |
404| :------------------------------------------- | :----- | :--------------------- |
405| SOURCE_TYPE_WAKEUP <sup>10+</sup>            | 3 | 语音唤醒音频流录制音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core <br/>**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE <br/> 此接口为系统接口|
406| SOURCE_TYPE_VOICE_CALL<sup>11+</sup>            | 4 | 通话录音的音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core<br/>**需要权限:** ohos.permission.RECORD_VOICE_CALL <br/> 此接口为系统接口|
407| SOURCE_TYPE_VOICE_TRANSCRIPTION<sup>18+</sup>   | 12     | 语音转写音频源。<br/>**系统能力:** SystemCapability.Multimedia.Audio.Core<br/> 此接口为系统接口|
408
409## VolumeAdjustType<sup>10+</sup>
410
411枚举,音量调节类型。
412
413**系统接口:** 该接口为系统接口
414
415**系统能力:** SystemCapability.Multimedia.Audio.Volume
416
417| 名称                   |  值     | 说明                                          |
418| :--------------------- | :----- | :-------------------------------------------- |
419| VOLUME_UP              | 0      | 向上调节音量。<br/>此接口为系统接口。   |
420| VOLUME_DOWN            | 1      | 向下调节音量。<br/>此接口为系统接口。   |
421
422## AudioManager
423
424管理音频音量和音频设备。在调用AudioManager的接口前,需要先通过[getAudioManager](js-apis-audio.md#audiogetaudiomanager)创建实例。
425
426### setExtraParameters<sup>11+</sup>
427
428setExtraParameters(mainKey: string, kvpairs: Record<string, string\>): Promise&lt;void&gt;
429
430音频扩展参数设置,使用Promise方式异步返回结果。
431
432**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS
433
434**系统接口:** 该接口为系统接口
435
436**系统能力:** SystemCapability.Multimedia.Audio.Core
437
438**参数:**
439
440| 参数名 | 类型   | 必填 | 说明                   |
441| ------ | ------ | ---- | ---------------------- |
442| mainKey | string | 是   | 被设置的音频参数的主键。 |
443| kvpairs | Record<string, string\> | 是   | 被设置的音频参数的子键值对。 |
444
445**返回值:**
446
447| 类型                | 说明                            |
448| ------------------- | ------------------------------- |
449| Promise&lt;void&gt; | Promise对象,无返回结果。 |
450
451**错误码:**
452
453以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
454
455| 错误码ID | 错误信息                                                                                                       |
456|-----|------------------------------------------------------------------------------------------------------------|
457| 201 | Permission denied. |
458| 202 | Not system App. |
459| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
460| 6800101 | Parameter verification failed. |
461
462**示例:**
463
464```ts
465import { BusinessError } from '@kit.BasicServicesKit';
466
467let kvpairs = {} as Record<string, string>;
468kvpairs = {
469  'key_example': 'value_example'
470};
471
472audioManager.setExtraParameters('key_example', kvpairs).then(() => {
473  console.info('Promise returned to indicate a successful setting of the extra parameters.');
474}).catch ((err: BusinessError) => {
475  console.error(`Failed to set the audio extra parameters ${err}`);
476});
477```
478
479### getExtraParameters<sup>11+</sup>
480
481getExtraParameters(mainKey: string, subKeys?: Array\<string>): Promise\<Record\<string, string>>
482
483获取指定音频参数值,使用Promise方式异步返回结果。
484
485**系统接口:** 该接口为系统接口
486
487**系统能力:** SystemCapability.Multimedia.Audio.Core
488
489**参数:**
490
491| 参数名 | 类型   | 必填 | 说明                   |
492| ------ | ------ |--| ---------------------- |
493| mainKey | string | 是 | 待获取的音频参数的主键。 |
494| subKeys | Array\<string> | 否 | 待获取的音频参数的子键。 |
495
496**返回值:**
497
498| 类型                  | 说明                                |
499| --------------------- | ----------------------------------- |
500| Promise\<Record\<string, string>> | Promise对象,返回获取的音频参数的值。 |
501
502**错误码:**
503
504以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
505
506| 错误码ID | 错误信息 |
507| ------ | -------------------------|
508| 202 | Not system App. |
509|  401  | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
510| 6800101 | Parameter verification failed. |
511
512**示例:**
513
514```ts
515import { BusinessError } from '@kit.BasicServicesKit';
516
517let subKeys: Array<String> = ['key_example'];
518audioManager.getExtraParameters('key_example', subKeys).then((value: Record<string, string>) => {
519  console.info(`Promise returned to indicate that the value of the audio extra parameters is obtained ${value}.`);
520}).catch ((err: BusinessError) => {
521  console.error(`Failed to get the audio extra parameters ${err}`);
522});
523```
524
525### setAudioScene<sup>8+</sup>
526
527setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
528
529设置音频场景模式,使用callback方式异步返回结果。
530
531**系统接口:** 该接口为系统接口
532
533**系统能力:** SystemCapability.Multimedia.Audio.Communication
534
535**参数:**
536
537| 参数名   | 类型                                 | 必填 | 说明                 |
538| :------- | :----------------------------------- | :--- | :------------------- |
539| scene    | [AudioScene](js-apis-audio.md#audioscene8) | 是   | 音频场景模式。       |
540| callback | AsyncCallback<void\>                 | 是   | 回调函数。当设置音频场景模式成功,err为undefined,否则为错误对象。 |
541
542**示例:**
543
544```ts
545import { BusinessError } from '@kit.BasicServicesKit';
546
547audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err: BusinessError) => {
548  if (err) {
549    console.error(`Failed to set the audio scene mode. ${err}`);
550    return;
551  }
552  console.info('Callback invoked to indicate a successful setting of the audio scene mode.');
553});
554```
555
556### setAudioScene<sup>8+</sup>
557
558setAudioScene\(scene: AudioScene\): Promise<void\>
559
560设置音频场景模式,使用Promise方式返回异步结果。
561
562**系统接口:** 该接口为系统接口
563
564**系统能力:** SystemCapability.Multimedia.Audio.Communication
565
566**参数:**
567
568| 参数名 | 类型                                 | 必填 | 说明           |
569| :----- | :----------------------------------- | :--- | :------------- |
570| scene  | [AudioScene](js-apis-audio.md#audioscene8) | 是   | 音频场景模式。 |
571
572**返回值:**
573
574| 类型           | 说明                 |
575| :------------- | :------------------- |
576| Promise<void\> | Promise对象,无返回结果。 |
577
578**示例:**
579
580```ts
581import { BusinessError } from '@kit.BasicServicesKit';
582
583audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
584  console.info('Promise returned to indicate a successful setting of the audio scene mode.');
585}).catch ((err: BusinessError) => {
586  console.error(`Failed to set the audio scene mode ${err}`);
587});
588```
589
590### getEffectManager<sup>18+</sup>
591
592getEffectManager(): AudioEffectManager
593
594获取音效会话管理器。
595
596**系统接口:** 该接口为系统接口
597
598**系统能力:** SystemCapability.Multimedia.Audio.Core
599
600**返回值:**
601
602| 类型                                           | 说明                          |
603|----------------------------------------------| ----------------------------- |
604| [AudioEffectManager](#audioeffectmanager18) | AudioEffectManager实例 |
605
606**错误码:**
607
608以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
609
610| 错误码ID | 错误信息 |
611| ------- | --------------------------------------------|
612| 202     | Not system App.                             |
613
614**示例:**
615
616```ts
617import { audio } from '@kit.AudioKit';
618
619let audioEffectManager: audio.AudioEffectManager = audioManager.getEffectManager();
620```
621
622### disableSafeMediaVolume<sup>12+</sup>
623
624disableSafeMediaVolume(): Promise&lt;void&gt;
625
626设置安全音量为非激活状态。使用Promise方式异步返回结果。
627
628设置为非激活状态后,当设备长时间高音量播放时,不再自动提醒用户降低到安全音量。
629
630**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS
631
632**系统接口:** 该接口为系统接口
633
634**系统能力:** SystemCapability.Multimedia.Audio.Core
635
636**返回值:**
637
638| 类型                                       | 说明                          |
639|------------------------------------------| ----------------------------- |
640| Promise&lt;void&gt; | Promise对象,无返回结果。 |
641
642**错误码:**
643
644以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
645
646| 错误码ID | 错误信息 |
647| ------- | --------------------------------------------|
648| 201     | Permission denied.                          |
649| 202     | Not system App.                             |
650
651**示例:**
652
653```ts
654import { BusinessError } from '@kit.BasicServicesKit';
655
656audioManager.disableSafeMediaVolume().then(() => {
657  console.info('disableSafeMediaVolume success.');
658}).catch ((err: BusinessError) => {
659  console.error(`disableSafeMediaVolume fail: ${err.code},${err.message}`);
660});
661```
662
663### on('volumeChange')<sup>(deprecated)</sup>
664
665on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
666
667> **说明:**
668> 从 API version 8 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeManager中的[on('volumeChange')](js-apis-audio.md#onvolumechange9)替代。
669
670监听系统音量变化事件(当系统音量发生变化时触发),使用callback方式返回结果。
671
672**系统接口:** 该接口为系统接口
673
674目前此订阅接口在单进程多AudioManager实例的使用场景下,仅最后一个实例的订阅生效,其他实例的订阅会被覆盖(即使最后一个实例没有进行订阅),因此推荐使用单一AudioManager实例进行开发。
675
676**系统能力:** SystemCapability.Multimedia.Audio.Volume
677
678**参数:**
679
680| 参数名   | 类型                                   | 必填 | 说明                                                         |
681| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
682| type     | string                                 | 是   | 监听事件,固定为:'volumeChange'。 |
683| callback | Callback<[VolumeEvent](#volumeevent9)> | 是   | 回调函数,返回变化后的音量信息。 |
684
685**示例:**
686
687```ts
688audioManager.on('volumeChange', (volumeEvent: audio.VolumeEvent) => {
689  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
690  console.info(`Volume level: ${volumeEvent.volume} `);
691  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
692});
693```
694
695### on('ringerModeChange')<sup>(deprecated)</sup>
696
697on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
698
699监听铃声模式变化事件(当[铃声模式](js-apis-audio.md#audioringmode)发生改变时触发),使用callback方式返回结果。
700
701> **说明:**
702> 从 API version 8 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[on('ringerModeChange')](js-apis-audio.md#onringermodechange9)替代。
703
704**系统接口:** 该接口为系统接口
705
706**系统能力:** SystemCapability.Multimedia.Audio.Communication
707
708**参数:**
709
710| 参数名   | 类型                                      | 必填 | 说明                                                         |
711| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
712| type     | string                                    | 是   | 监听事件,固定为:'ringerModeChange'。 |
713| callback | Callback<[AudioRingMode](js-apis-audio.md#audioringmode)> | 是   | 回调函数,返回变化后的铃音模式。                                                   |
714
715**示例:**
716
717```ts
718audioManager.on('ringerModeChange', (ringerMode: audio.AudioRingMode) => {
719  console.info(`Updated ringermode: ${ringerMode}`);
720});
721```
722
723## AudioVolumeManager<sup>9+</sup>
724
725音量管理。在使用AudioVolumeManager的接口前,需要使用[getVolumeManager](js-apis-audio.md#getvolumemanager9)获取AudioVolumeManager实例。
726
727### getVolumeGroupInfos<sup>9+</sup>
728
729getVolumeGroupInfos(networkId: string, callback: AsyncCallback<VolumeGroupInfos\>\): void
730
731获取音量组信息列表,使用callback方式异步返回结果。
732
733**系统接口:** 该接口为系统接口
734
735**系统能力:** SystemCapability.Multimedia.Audio.Volume
736
737**参数:**
738
739| 参数名     | 类型                                                         | 必填 | 说明                 |
740| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
741| networkId | string                                    | 是   | 设备的网络id。本地设备audio.LOCAL_NETWORK_ID。    |
742| callback  | AsyncCallback&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | 是   | 回调函数。当获取音量组信息列表成功,err为undefined,data为获取到的音量组信息列表;否则为错误对象。 |
743
744**示例:**
745```ts
746import { BusinessError } from '@kit.BasicServicesKit';
747
748audioVolumeManager.getVolumeGroupInfos(audio.LOCAL_NETWORK_ID, (err: BusinessError, value: audio.VolumeGroupInfos) => {
749  if (err) {
750    console.error(`Failed to obtain the volume group infos list. ${err}`);
751    return;
752  }
753  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
754});
755```
756
757### getVolumeGroupInfos<sup>9+</sup>
758
759getVolumeGroupInfos(networkId: string\): Promise<VolumeGroupInfos\>
760
761获取音量组信息列表,使用Promise方式异步返回结果。
762
763**系统接口:** 该接口为系统接口
764
765**系统能力:** SystemCapability.Multimedia.Audio.Volume
766
767**参数:**
768
769| 参数名     | 类型               | 必填 | 说明                 |
770| ---------- | ------------------| ---- | -------------------- |
771| networkId | string             | 是   | 设备的网络id。本地设备audio.LOCAL_NETWORK_ID。   |
772
773**返回值:**
774
775| 类型                | 说明                          |
776| ------------------- | ----------------------------- |
777| Promise&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Promise对象,返回音量组信息列表。 |
778
779**示例:**
780
781```ts
782async function getVolumeGroupInfos(){
783  let volumegroupinfos: audio.VolumeGroupInfos = await audio.getAudioManager().getVolumeManager().getVolumeGroupInfos(audio.LOCAL_NETWORK_ID);
784  console.info('Promise returned to indicate that the volumeGroup list is obtained.'+JSON.stringify(volumegroupinfos))
785}
786```
787
788### getVolumeGroupInfosSync<sup>10+</sup>
789
790getVolumeGroupInfosSync(networkId: string\): VolumeGroupInfos
791
792获取音量组信息列表,同步返回结果。
793
794**系统接口:** 该接口为系统接口
795
796**系统能力:** SystemCapability.Multimedia.Audio.Volume
797
798**参数:**
799
800| 参数名     | 类型               | 必填 | 说明                 |
801| ---------- | ------------------| ---- | -------------------- |
802| networkId | string             | 是   | 设备的网络id。本地设备audio.LOCAL_NETWORK_ID。   |
803
804**返回值:**
805
806| 类型                | 说明                          |
807| ------------------- | ----------------------------- |
808| [VolumeGroupInfos](#volumegroupinfos9) | 音量组信息列表。 |
809
810**错误码:**
811
812以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
813
814| 错误码ID | 错误信息 |
815| ------- | --------------------------------------------|
816| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
817| 6800101 | Parameter verification failed. |
818
819**示例:**
820
821```ts
822import { BusinessError } from '@kit.BasicServicesKit';
823
824try {
825  let volumegroupinfos: audio.VolumeGroupInfos = audioVolumeManager.getVolumeGroupInfosSync(audio.LOCAL_NETWORK_ID);
826  console.info(`Indicate that the volumeGroup list is obtained. ${JSON.stringify(volumegroupinfos)}`);
827} catch (err) {
828  let error = err as BusinessError;
829  console.error(`Failed to obtain the volumeGroup list ${error}`);
830}
831```
832
833### getAppVolumePercentageForUid<sup>18+</sup>
834
835getAppVolumePercentageForUid(uid: number\): Promise<number\>
836
837根据应用ID获取指定应用的音量(范围为0到100)。使用Promise异步回调。
838
839**系统接口:** 该接口为系统接口。
840
841**系统能力:** SystemCapability.Multimedia.Audio.Volume
842
843**参数:**
844
845| 参数名     | 类型                                      | 必填 | 说明                               |
846| ---------- | ---------------------------------------- | ---- |----------------------------------|
847| uid    | number                                   | 是   | 表示应用ID。 |
848
849**返回值:**
850
851| 类型                | 说明                          |
852| ------------------- | ----------------------------- |
853| Promise&lt;number&gt; | Promise对象,返回应用的音量(范围为0到100)。 |
854
855**错误码:**
856
857以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
858
859| 错误码ID | 错误信息 |
860| ------- | --------------------------------------------|
861| 201 | Permission denied. |
862| 202 | Not system App. |
863| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
864| 6800101 | Parameter verification failed.|
865
866**示例:**
867
868```ts
869let uid: number = 20010041; // 应用ID。
870
871audioVolumeManager.getAppVolumePercentageForUid(20010041).then((value: number) => {
872  console.info(`app volume is ${value}.`);
873});
874```
875
876### setAppVolumePercentageForUid<sup>18+</sup>
877
878setAppVolumePercentageForUid(uid: number, volume: number\): Promise<void\>
879
880根据应用ID设置指定应用的音量(范围为0到100)。使用Promise异步回调。
881
882**系统接口:** 该接口为系统接口。
883
884**系统能力:** SystemCapability.Multimedia.Audio.Volume
885
886**参数:**
887
888| 参数名     | 类型                                      | 必填 | 说明       |
889| ---------- | ---------------------------------------- | ---- |----------|
890| uid    | number                                   | 是   | 表示应用ID。   |
891| volume    | number                                   | 是   | 要设置的音量值。 |
892
893**返回值:**
894
895| 类型                | 说明                            |
896| ------------------- | ------------------------------- |
897| Promise&lt;void&gt; | Promise对象,无返回结果。 |
898
899**错误码:**
900
901以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
902
903| 错误码ID | 错误信息 |
904| ------- | --------------------------------------------|
905| 201 | Permission denied. |
906| 202 | Not system App. |
907| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
908| 6800101 | Parameter verification failed.|
909| 6800301 | Crash or blocking occurs in system process. |
910
911**示例:**
912
913```ts
914let uid: number = 20010041; // 应用ID。
915let volume: number = 20;    // 要设置的音量值。
916
917audioVolumeManager.setAppVolumePercentageForUid(uid, volume).then(() => {
918  console.info(`set app volume success.`);
919});
920```
921
922### isAppVolumeMutedForUid<sup>18+</sup>
923
924isAppVolumeMutedForUid(uid: number, owned: boolean\): Promise<boolean\>
925
926根据应用ID查询应用音量是否已静音。使用Promise异步回调。
927
928> **说明:**
929>
930> 如果有多个调用者设置了静音状态,那么只有当所有调用者都取消静音状态后,此应用才会真正取消静音。
931
932**系统接口:** 该接口为系统接口。
933
934**系统能力:** SystemCapability.Multimedia.Audio.Volume
935
936**参数:**
937
938| 参数名     | 类型                                      | 必填 | 说明                                        |
939| ---------- | ---------------------------------------- | ---- |-------------------------------------------|
940| uid    | number                                   | 是   | 表示应用ID。                                    |
941| owned    | boolean                                   | 是   | 要查询的静音状态。true查询当前调用者的静音状态,false查询应用的静音状态。 |
942
943**返回值:**
944
945| 类型                | 说明                  |
946| ------------------- |---------------------|
947| Promise&lt;boolean&gt; | Promise对象。返回true表示应用为静音状态;返回false表示应用为非静音状态。 |
948
949**错误码:**
950
951以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
952
953| 错误码ID | 错误信息 |
954| ------- | --------------------------------------------|
955| 201 | Permission denied. |
956| 202 | Not system App. |
957| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
958| 6800101 |  Parameter verification failed.|
959
960**示例:**
961
962```ts
963let uid: number = 20010041; // 应用ID。
964
965audioVolumeManager.setAppVolumePercentageForUid(uid, true).then((value: boolean) => {
966  console.info(`app muted state is ${value}.`);
967});
968```
969
970### setAppVolumeMutedForUid<sup>18+</sup>
971
972setAppVolumeMutedForUid(uid: number, muted: boolean\): Promise<void\>
973
974根据应用ID设置应用静音状态。使用Promise异步回调。
975
976**系统接口:** 该接口为系统接口。
977
978**系统能力:** SystemCapability.Multimedia.Audio.Volume
979
980**参数:**
981
982| 参数名     | 类型                                      | 必填 | 说明                             |
983| ---------- | ---------------------------------------- | ---- |--------------------------------|
984| uid    | number                                   | 是   | 表示应用ID。                         |
985| owned    | boolean                                   | 是   | 设置应用的静音状态。true设置为静音,false解除静音。 |
986
987**返回值:**
988
989| 类型                | 说明                            |
990| ------------------- | ------------------------------- |
991| Promise&lt;void&gt; | Promise对象,无返回结果。 |
992
993**错误码:**
994
995以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
996
997| 错误码ID | 错误信息 |
998| ------- | --------------------------------------------|
999| 201 | Permission denied. |
1000| 202 | Not system App. |
1001| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1002| 6800101 | Parameter verification failed.|
1003| 6800301 | Crash or blocking occurs in system process. |
1004
1005**示例:**
1006
1007```ts
1008let uid: number = 20010041; // 应用ID。
1009
1010audioVolumeManager.setAppVolumePercentageForUid(uid, true).then(() => {
1011  console.info(`set app mute state success.`);
1012});
1013```
1014
1015### on('appVolumeChangeForUid')<sup>18+</sup>
1016
1017on(type: 'appVolumeChangeForUid', uid: number, callback: Callback\<VolumeEvent>): void
1018
1019监听指定应用应用级音量变化事件(当应用级音量发生变化时触发)。使用callback方式返回结果。
1020
1021**系统接口:** 该接口为系统接口。
1022
1023**系统能力:** SystemCapability.Multimedia.Audio.Volume
1024
1025**参数:**
1026
1027| 参数名   | 类型                                   | 必填 | 说明                                |
1028| -------- | -------------------------------------- | ---- |-----------------------------------|
1029| type     | string                                 | 是   | 监听事件,固定为:'appVolumeChangeForUid'。 |
1030| uid | number |  是   | 表示应用ID。                          |
1031| callback | Callback<[VolumeEvent](js-apis-audio.md#volumeevent9)> | 是   | 回调函数,返回变化后的音量信息。                  |
1032
1033**错误码:**
1034
1035以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
1036
1037| 错误码ID | 错误信息 |
1038| ------- | --------------------------------------------|
1039| 201 | Permission denied. |
1040| 202 | Not system App. |
1041| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1042| 6800101 | Parameter verification failed. |
1043
1044**示例:**
1045
1046```ts
1047let uid: number = 20010041; // 应用ID。
1048
1049audioVolumeManager.on('appVolumeChangeForUid', uid, (volumeEvent: audio.VolumeEvent) => {
1050  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
1051  console.info(`Volume level: ${volumeEvent.volume} `);
1052  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
1053});
1054```
1055
1056### off('appVolumeChangeForUid')<sup>18+</sup>
1057
1058off(type: 'appVolumeChangeForUid', callback?: Callback\<VolumeEvent>): void
1059
1060取消监听指定应用应用级音量变化事件。使用callback方式返回结果。
1061
1062**系统接口:** 该接口为系统接口。
1063
1064**系统能力:** SystemCapability.Multimedia.Audio.Volume
1065
1066**参数:**
1067
1068| 参数名   | 类型                                   | 必填 | 说明                                                         |
1069| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
1070| type     | string                                 | 是   | 监听事件,固定为:'appVolumeChangeForUid'。 |
1071| callback | Callback<[VolumeEvent](js-apis-audio.md#volumeevent9)> | 否   | 回调函数,返回变化后的音量信息。 |
1072
1073**错误码:**
1074
1075以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
1076
1077| 错误码ID | 错误信息 |
1078| ------- | --------------------------------------------|
1079| 201 | Permission denied. |
1080| 202 | Not system App. |
1081| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1082| 6800101 | Parameter verification failed. |
1083
1084**示例:**
1085
1086```ts
1087// 取消该事件的所有监听。
1088audioVolumeManager.off('appVolumeChangeForUid');
1089
1090// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听。
1091let appVolumeChangeForUidCallback = (volumeEvent: audio.VolumeEvent) => {
1092  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
1093  console.info(`Volume level: ${volumeEvent.volume} `);
1094  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
1095};
1096
1097audioVolumeManager.on('appVolumeChangeForUid', appVolumeChangeForUidCallback);
1098
1099audioVolumeManager.off('appVolumeChangeForUid', appVolumeChangeForUidCallback);
1100```
1101
1102## AudioVolumeGroupManager<sup>9+</sup>
1103
1104管理音频组音量。在调用AudioVolumeGroupManager的接口前,需要先通过 [getVolumeGroupManager](js-apis-audio.md#getvolumegroupmanager9) 创建实例。
1105
1106### setVolume<sup>9+</sup>
1107
1108setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
1109
1110设置指定流的音量,使用callback方式异步返回结果。
1111
1112**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1113
1114仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1115
1116**系统接口:** 该接口为系统接口
1117
1118**系统能力:** SystemCapability.Multimedia.Audio.Volume
1119
1120**参数:**
1121
1122| 参数名     | 类型                                | 必填 | 说明                                                     |
1123| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1124| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
1125| volume     | number                              | 是   | 音量等级,可设置范围通过[getMinVolume](js-apis-audio.md#getminvolume9)和[getMaxVolume](js-apis-audio.md#getmaxvolume9)获取。 |
1126| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调函数。当设置指定流的音量成功,err为undefined,否则为错误对象。 |
1127
1128**示例:**
1129
1130```ts
1131import { BusinessError } from '@kit.BasicServicesKit';
1132
1133audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err: BusinessError) => {
1134  if (err) {
1135    console.error(`Failed to set the volume. ${err}`);
1136    return;
1137  }
1138  console.info('Callback invoked to indicate a successful volume setting.');
1139});
1140```
1141
1142### setVolume<sup>9+</sup>
1143
1144setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
1145
1146设置指定流的音量,使用Promise方式异步返回结果。
1147
1148**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1149
1150仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1151
1152**系统接口:** 该接口为系统接口
1153
1154**系统能力:** SystemCapability.Multimedia.Audio.Volume
1155
1156**参数:**
1157
1158| 参数名     | 类型                                | 必填 | 说明                                                     |
1159| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1160| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
1161| volume     | number                              | 是   | 音量等级,可设置范围通过[getMinVolume](js-apis-audio.md#getminvolume9)和[getMaxVolume](js-apis-audio.md#getmaxvolume9)获取。 |
1162
1163**返回值:**
1164
1165| 类型                | 说明                          |
1166| ------------------- | ----------------------------- |
1167| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1168
1169**示例:**
1170
1171```ts
1172audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
1173  console.info('Promise returned to indicate a successful volume setting.');
1174});
1175```
1176
1177### setVolumeWithFlag<sup>12+</sup>
1178
1179setVolumeWithFlag(volumeType: AudioVolumeType, volume: number, flags: number): Promise&lt;void&gt;
1180
1181设置指定流的音量,同时指定本次修改音量是否要显示系统音量条,使用Promise方式异步返回结果。
1182
1183**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1184
1185仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1186
1187**系统接口:** 该接口为系统接口
1188
1189**系统能力:** SystemCapability.Multimedia.Audio.Volume
1190
1191**参数:**
1192
1193| 参数名     | 类型                                | 必填 | 说明                                   |
1194| ---------- | ----------------------------------- | ---- |--------------------------------------|
1195| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                               |
1196| volume     | number                              | 是   | 音量等级,可设置范围通过[getMinVolume](js-apis-audio.md#getminvolume9)和[getMaxVolume](js-apis-audio.md#getmaxvolume9)获取。 |
1197| flags      | number                              | 是   | 是否需要显示系统音量条,0为不需要显示,1为需要显示。 |
1198
1199**返回值:**
1200
1201| 类型                | 说明                          |
1202| ------------------- | ----------------------------- |
1203| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1204
1205**错误码:**
1206
1207以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
1208
1209| 错误码ID | 错误信息 |
1210| ------- | --------------------------------------------|
1211| 201     | Permission denied.                          |
1212| 202     | Not system App.                             |
1213
1214**示例:**
1215
1216```ts
1217audioVolumeGroupManager.setVolumeWithFlag(audio.AudioVolumeType.MEDIA, 10, 1).then(() => {
1218  console.info('Promise returned to indicate a successful volume setting.');
1219});
1220```
1221
1222### mute<sup>9+</sup>
1223
1224mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1225
1226设置指定音量流静音,使用callback方式异步返回结果。
1227
1228**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1229
1230仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1231
1232**系统接口:** 该接口为系统接口
1233
1234**系统能力:** SystemCapability.Multimedia.Audio.Volume
1235
1236**参数:**
1237
1238| 参数名     | 类型                                | 必填 | 说明                                  |
1239| ---------- | ----------------------------------- | ---- | ------------------------------------- |
1240| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                          |
1241| mute       | boolean                             | 是   | 静音状态,true为静音,false为非静音。 |
1242| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调函数。当设置指定音量流静音成功,err为undefined,否则为错误对象。 |
1243
1244**示例:**
1245
1246```ts
1247import { BusinessError } from '@kit.BasicServicesKit';
1248
1249audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true, (err: BusinessError) => {
1250  if (err) {
1251    console.error(`Failed to mute the stream. ${err}`);
1252    return;
1253  }
1254  console.info('Callback invoked to indicate that the stream is muted.');
1255});
1256```
1257
1258### mute<sup>9+</sup>
1259
1260mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
1261
1262设置指定音量流静音,使用Promise方式异步返回结果。
1263
1264**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1265
1266仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1267
1268**系统接口:** 该接口为系统接口
1269
1270**系统能力:** SystemCapability.Multimedia.Audio.Volume
1271
1272**参数:**
1273
1274| 参数名     | 类型                                | 必填 | 说明                                  |
1275| ---------- | ----------------------------------- | ---- | ------------------------------------- |
1276| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                          |
1277| mute       | boolean                             | 是   | 静音状态,true为静音,false为非静音。 |
1278
1279**返回值:**
1280
1281| 类型                | 说明                          |
1282| ------------------- | ----------------------------- |
1283| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1284
1285**示例:**
1286
1287```ts
1288audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
1289  console.info('Promise returned to indicate that the stream is muted.');
1290});
1291```
1292
1293### setRingerMode<sup>9+</sup>
1294
1295setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
1296
1297设置铃声模式,使用callback方式异步返回结果。
1298
1299**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1300
1301仅在静音和非静音状态切换时需要该权限。
1302
1303**系统接口:** 该接口为系统接口
1304
1305**系统能力:** SystemCapability.Multimedia.Audio.Volume
1306
1307**参数:**
1308
1309| 参数名   | 类型                            | 必填 | 说明                     |
1310| -------- | ------------------------------- | ---- | ------------------------ |
1311| mode     | [AudioRingMode](js-apis-audio.md#audioringmode) | 是   | 音频铃声模式。           |
1312| callback | AsyncCallback&lt;void&gt;       | 是   | 回调函数。当设置铃声模式成功,err为undefined,否则为错误对象。 |
1313
1314**示例:**
1315
1316```ts
1317import { BusinessError } from '@kit.BasicServicesKit';
1318
1319audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err: BusinessError) => {
1320  if (err) {
1321    console.error(`Failed to set the ringer mode. ${err}`);
1322    return;
1323  }
1324  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
1325});
1326```
1327
1328### setRingerMode<sup>9+</sup>
1329
1330setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
1331
1332设置铃声模式,使用Promise方式异步返回结果。
1333
1334**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1335
1336仅在静音和非静音状态切换时需要该权限。
1337
1338**系统接口:** 该接口为系统接口
1339
1340**系统能力:** SystemCapability.Multimedia.Audio.Volume
1341
1342**参数:**
1343
1344| 参数名 | 类型                            | 必填 | 说明           |
1345| ------ | ------------------------------- | ---- | -------------- |
1346| mode   | [AudioRingMode](js-apis-audio.md#audioringmode) | 是   | 音频铃声模式。 |
1347
1348**返回值:**
1349
1350| 类型                | 说明                            |
1351| ------------------- | ------------------------------- |
1352| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1353
1354**示例:**
1355
1356```ts
1357audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
1358  console.info('Promise returned to indicate a successful setting of the ringer mode.');
1359});
1360```
1361
1362### setMicMute<sup>11+</sup>
1363
1364setMicMute(mute: boolean): Promise&lt;void&gt;
1365
1366设置麦克风静音状态,使用Promise方式异步返回结果。
1367
1368**需要权限:** ohos.permission.MANAGE_AUDIO_CONFIG
1369
1370**系统接口:** 该接口为系统接口
1371
1372**系统能力:** SystemCapability.Multimedia.Audio.Volume
1373
1374**参数:**
1375
1376| 参数名 | 类型    | 必填 | 说明                                          |
1377| ------ | ------- | ---- | --------------------------------------------- |
1378| mute   | boolean | 是   | 待设置的静音状态,true为静音,false为非静音。 |
1379
1380**返回值:**
1381
1382| 类型                | 说明                            |
1383| ------------------- | ------------------------------- |
1384| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1385
1386**错误码:**
1387
1388以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
1389
1390| 错误码ID | 错误信息 |
1391| ------- | --------------------------------------------|
1392| 201     | Permission denied.                          |
1393| 202     | Not system App.                             |
1394| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1395| 6800101 | Parameter verification failed. |
1396
1397**示例:**
1398
1399```ts
1400audioVolumeGroupManager.setMicMute(true).then(() => {
1401  console.info('Promise returned to indicate that the mic is muted.');
1402});
1403```
1404
1405### adjustVolumeByStep<sup>10+</sup>
1406
1407adjustVolumeByStep(adjustType: VolumeAdjustType, callback: AsyncCallback&lt;void&gt;): void
1408
1409调节当前最高优先级的流的音量,使音量值按步长加或减,使用callback方式异步返回结果。
1410
1411**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1412
1413仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1414
1415**系统接口:** 该接口为系统接口
1416
1417**系统能力:** SystemCapability.Multimedia.Audio.Volume
1418
1419**参数:**
1420
1421| 参数名     | 类型                                | 必填 | 说明                                                     |
1422| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1423| adjustType | [VolumeAdjustType](#volumeadjusttype10) | 是   | 音量调节方向。                                             |
1424| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调函数。当调节当前最高优先级的流的音量成功,err为undefined,否则为错误对象。 |
1425
1426**错误码:**
1427
1428以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
1429
1430| 错误码ID | 错误信息 |
1431| ------- | --------------------------------------------|
1432| 201 | Permission denied. |
1433| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1434| 6800101 | Parameter verification failed. Return by callback.                     |
1435| 6800301 | System error. Return by callback.                                |
1436
1437**示例:**
1438
1439```ts
1440import { BusinessError } from '@kit.BasicServicesKit';
1441
1442audioVolumeGroupManager.adjustVolumeByStep(audio.VolumeAdjustType.VOLUME_UP, (err: BusinessError) => {
1443  if (err) {
1444    console.error(`Failed to adjust the volume by step. ${err}`);
1445    return;
1446  } else {
1447    console.info('Success to adjust the volume by step.');
1448  }
1449});
1450```
1451### adjustVolumeByStep<sup>10+</sup>
1452
1453adjustVolumeByStep(adjustType: VolumeAdjustType): Promise&lt;void&gt;
1454
1455单步设置当前最高优先级的流的音量,使用Promise方式异步返回结果。
1456
1457**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1458
1459仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1460
1461**系统接口:** 该接口为系统接口
1462
1463**系统能力:** SystemCapability.Multimedia.Audio.Volume
1464
1465**参数:**
1466
1467| 参数名     | 类型                                | 必填 | 说明                                                     |
1468| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1469| adjustType | [VolumeAdjustType](#volumeadjusttype10) | 是   | 音量调节方向。                                             |
1470
1471**返回值:**
1472
1473| 类型                | 说明                          |
1474| ------------------- | ----------------------------- |
1475| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1476
1477**错误码:**
1478
1479以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
1480
1481| 错误码ID | 错误信息 |
1482| ------- | --------------------------------------------|
1483| 201 | Permission denied. |
1484| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1485| 6800101 | Parameter verification failed. Return by promise.                     |
1486| 6800301 | System error. Return by promise.                                |
1487
1488**示例:**
1489
1490```ts
1491import { BusinessError } from '@kit.BasicServicesKit';
1492
1493audioVolumeGroupManager.adjustVolumeByStep(audio.VolumeAdjustType.VOLUME_UP).then(() => {
1494  console.info('Success to adjust the volume by step.');
1495}).catch((error: BusinessError) => {
1496  console.error('Fail to adjust the volume by step.');
1497});
1498```
1499
1500### adjustSystemVolumeByStep<sup>10+</sup>
1501
1502adjustSystemVolumeByStep(volumeType: AudioVolumeType, adjustType: VolumeAdjustType, callback: AsyncCallback&lt;void&gt;): void
1503
1504单步设置指定流的音量,使用callback方式异步返回结果。
1505
1506**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1507
1508仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1509
1510**系统接口:** 该接口为系统接口
1511
1512**系统能力:** SystemCapability.Multimedia.Audio.Volume
1513
1514**参数:**
1515
1516| 参数名     | 类型                                | 必填 | 说明                                                     |
1517| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1518| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
1519| adjustType | [VolumeAdjustType](#volumeadjusttype10) | 是   | 音量调节方向。                                       |
1520| callback   | AsyncCallback&lt;void&gt;           | 是   | 回调函数。当单步设置指定流的音量成功,err为undefined,否则为错误对象。 |
1521
1522**错误码:**
1523
1524以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
1525
1526| 错误码ID | 错误信息 |
1527| ------- | --------------------------------------------|
1528| 201 | Permission denied. |
1529| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1530| 6800101 | Parameter verification failed. Return by callback.                     |
1531| 6800301 | System error. Return by callback.                                |
1532
1533**示例:**
1534
1535```ts
1536import { BusinessError } from '@kit.BasicServicesKit';
1537
1538audioVolumeGroupManager.adjustSystemVolumeByStep(audio.AudioVolumeType.MEDIA, audio.VolumeAdjustType.VOLUME_UP, (err: BusinessError) => {
1539  if (err) {
1540    console.error(`Failed to adjust the system volume by step ${err}`);
1541  } else {
1542    console.info('Success to adjust the system volume by step.');
1543  }
1544});
1545```
1546### adjustSystemVolumeByStep<sup>10+</sup>
1547
1548adjustSystemVolumeByStep(volumeType: AudioVolumeType, adjustType: VolumeAdjustType): Promise&lt;void&gt;
1549
1550单步设置指定流的音量,使用Promise方式异步返回结果。
1551
1552**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
1553
1554仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
1555
1556**系统接口:** 该接口为系统接口
1557
1558**系统能力:** SystemCapability.Multimedia.Audio.Volume
1559
1560**参数:**
1561
1562| 参数名     | 类型                                | 必填 | 说明                                                     |
1563| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
1564| volumeType | [AudioVolumeType](#audiovolumetype) | 是   | 音量流类型。                                             |
1565| adjustType | [VolumeAdjustType](#volumeadjusttype10) | 是   | 音量调节方向。                                             |
1566
1567**返回值:**
1568
1569| 类型                | 说明                          |
1570| ------------------- | ----------------------------- |
1571| Promise&lt;void&gt; | Promise对象,无返回结果。 |
1572
1573**错误码:**
1574
1575以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
1576
1577| 错误码ID | 错误信息 |
1578| -------- | --------------------------------------------|
1579| 201 | Permission denied. |
1580| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1581| 6800101 | Parameter verification failed. Return by promise.                     |
1582| 6800301 | System error. Return by promise.                                |
1583
1584**示例:**
1585
1586```ts
1587import { BusinessError } from '@kit.BasicServicesKit';
1588
1589audioVolumeGroupManager.adjustSystemVolumeByStep(audio.AudioVolumeType.MEDIA, audio.VolumeAdjustType.VOLUME_UP).then(() => {
1590  console.info('Success to adjust the system volume by step.');
1591}).catch((error: BusinessError) => {
1592  console.error('Fail to adjust the system volume by step.');
1593});
1594```
1595## AudioEffectManager<sup>18+</sup>
1596
1597音频效果管理。在使用AudioEffectManager的接口前,需要使用[getEffectManager](#geteffectmanager18)获取AudioEffectManager实例。
1598
1599
1600### getSupportedAudioEffectProperty<sup>18+</sup>
1601
1602getSupportedAudioEffectProperty(): Array\<AudioEffectProperty>
1603
1604获取支持的下行音效模式,同步返回结果。
1605
1606**需要权限:** ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
1607
1608**系统接口:** 该接口为系统接口
1609
1610**系统能力:** SystemCapability.Multimedia.Audio.Core
1611
1612**返回值:**
1613
1614| 类型                                                                      | 说明                                    |
1615| --------------------------------------------------------------------------| --------------------------------------- |
1616| Array\<[AudioEffectProperty](#audioeffectproperty18)>     | 返回当前设备支持的音效模式。              |
1617
1618**错误码:**
1619
1620以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
1621
1622| 错误码ID | 错误信息 |
1623| ------- | --------------------------------------------|
1624| 201 | Permission denied. |
1625| 202 | Caller is not a system application. |
1626| 6800301 | System error. Return by callback. |
1627
1628**示例:**
1629
1630```ts
1631import { BusinessError } from '@kit.BasicServicesKit';
1632
1633try {
1634  let propertyArray: Array<audio.AudioEffectProperty> = audioStreamManager.getSupportedAudioEffectProperty();
1635  console.info(`The effect modes are: ${propertyArray}`);
1636} catch (err) {
1637  let error = err as BusinessError;
1638  console.error(`getSupportedAudioEffectProperty ERROR: ${error}`);
1639}
1640```
1641
1642
1643### getAudioEffectProperty<sup>18+</sup>
1644
1645getAudioEffectProperty(): Array\<AudioEffectProperty>
1646
1647获取当前音效模式,同步返回结果。
1648
1649**需要权限:** ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
1650
1651**系统接口:** 该接口为系统接口
1652
1653**系统能力:** SystemCapability.Multimedia.Audio.Core
1654
1655**返回值:**
1656
1657| 类型                                                                      | 说明                                    |
1658| --------------------------------------------------------------------------| --------------------------------------- |
1659| Array\<[AudioEffectProperty](#audioeffectproperty18)>     | 返回当前音效模式。                        |
1660
1661**错误码:**
1662
1663以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
1664
1665| 错误码ID | 错误信息 |
1666| ------- | --------------------------------------------|
1667| 201 | Permission denied. |
1668| 202 | Caller is not a system application. |
1669| 6800301 | System error. Return by callback. |
1670
1671**示例:**
1672
1673```ts
1674import { BusinessError } from '@kit.BasicServicesKit';
1675
1676try {
1677  let propertyArray: Array<audio.AudioEffectProperty> = audioStreamManager.getAudioEffectProperty();
1678  console.info(`The effect modes are: ${propertyArray}`);
1679} catch (err) {
1680  let error = err as BusinessError;
1681  console.error(`getAudioEffectProperty ERROR: ${error}`);
1682}
1683```
1684
1685### setAudioEffectProperty<sup>18+</sup>
1686
1687setAudioEffectProperty(propertyArray: Array\<AudioEffectProperty>): void
1688
1689设置当前音效模式,同步返回结果。
1690
1691**需要权限:** ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
1692
1693**系统接口:** 该接口为系统接口
1694
1695**系统能力:** SystemCapability.Multimedia.Audio.core
1696
1697**参数:**
1698| 参数名        | 类型                                                  | 必填     | 说明                         |
1699| ------------- | ----------------------------------------------------- | -------- | ---------------------------- |
1700| propertyArray | Array\<[AudioEffectProperty](#audioeffectproperty18)> | 是       |  需要设置的音效模式。        |
1701
1702**错误码:**
1703
1704以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
1705
1706| 错误码ID | 错误信息 |
1707| ------- | --------------------------------------------|
1708| 201 | Permission denied. |
1709| 202 | Caller is not a system application. |
1710| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1711| 6800101 | Parameter verification failed. Possible causes: 1.more than one enhanceProps of the same enhanceClass in input Array; 2.input audioEnhanceProperties are not supported by current device. 3.names of enhanceProp or enhanceClass are incorrect.|
1712| 6800301 | System error. Return by callback. |
1713
1714**示例:**
1715
1716```ts
1717import { BusinessError } from '@kit.BasicServicesKit';
1718
1719try {
1720  let propertyArray: Array<audio.AudioEffectProperty> = audioEffectManager.getAudioEffectProperty();
1721  console.info(`The effect modes are: ${propertyArray}`);
1722  audioEffectManager.setAudioEffectProperty(propertyArray);
1723} catch (err) {
1724  let error = err as BusinessError;
1725  console.error(`setAudioEffectProperty ERROR: ${error}`);
1726}
1727```
1728
1729## AudioRoutingManager<sup>9+</sup>
1730
1731音频路由管理。在使用AudioRoutingManager的接口前,需要使用[getRoutingManager](js-apis-audio.md#getroutingmanager9)获取AudioRoutingManager实例。
1732
1733### selectInputDevice<sup>9+</sup>
1734
1735selectInputDevice(inputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
1736
1737选择音频输入设备,当前只能选择一个输入设备,使用callback方式异步返回结果。
1738
1739**系统接口:** 该接口为系统接口
1740
1741**系统能力:** SystemCapability.Multimedia.Audio.Device
1742
1743**参数:**
1744
1745| 参数名                       | 类型                                                         | 必填 | 说明                      |
1746| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
1747| inputAudioDevices           | [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors)            | 是   | 输入设备类。               |
1748| callback                    | AsyncCallback&lt;void&gt;                                    | 是   | 回调函数。当选择音频输入设备成功,err为undefined,否则为错误对象。 |
1749
1750**示例:**
1751```ts
1752import { audio } from '@kit.AudioKit';
1753import { BusinessError } from '@kit.BasicServicesKit';
1754
1755let inputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
1756  deviceRole : audio.DeviceRole.INPUT_DEVICE,
1757  deviceType : audio.DeviceType.MIC,
1758  id : 1,
1759  name : "",
1760  address : "",
1761  sampleRates : [44100],
1762  channelCounts : [2],
1763  channelMasks : [0],
1764  networkId : audio.LOCAL_NETWORK_ID,
1765  interruptGroupId : 1,
1766  volumeGroupId : 1,
1767  displayName : "",
1768}];
1769
1770async function selectInputDevice(){
1771  audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor, (err: BusinessError) => {
1772    if (err) {
1773      console.error(`Result ERROR: ${err}`);
1774    } else {
1775      console.info('Select input devices result callback: SUCCESS');
1776    }
1777  });
1778}
1779```
1780
1781### selectInputDevice<sup>9+</sup>
1782
1783selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
1784
1785**系统接口:** 该接口为系统接口
1786
1787选择音频输入设备,当前只能选择一个输入设备,使用Promise方式异步返回结果。
1788
1789**系统能力:** SystemCapability.Multimedia.Audio.Device
1790
1791**参数:**
1792
1793| 参数名                       | 类型                                                         | 必填 | 说明                      |
1794| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
1795| inputAudioDevices           | [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors)            | 是   | 输入设备类。               |
1796
1797**返回值:**
1798
1799| 类型                  | 说明                         |
1800| --------------------- | --------------------------- |
1801| Promise&lt;void&gt;   | Promise对象,无返回结果。 |
1802
1803**示例:**
1804
1805```ts
1806import { audio } from '@kit.AudioKit';
1807import { BusinessError } from '@kit.BasicServicesKit';
1808
1809let inputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
1810  deviceRole : audio.DeviceRole.INPUT_DEVICE,
1811  deviceType : audio.DeviceType.MIC,
1812  id : 1,
1813  name : "",
1814  address : "",
1815  sampleRates : [44100],
1816  channelCounts : [2],
1817  channelMasks : [0],
1818  networkId : audio.LOCAL_NETWORK_ID,
1819  interruptGroupId : 1,
1820  volumeGroupId : 1,
1821  displayName : "",
1822}];
1823
1824async function getRoutingManager(){
1825  audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => {
1826    console.info('Select input devices result promise: SUCCESS');
1827  }).catch((err: BusinessError) => {
1828    console.error(`Result ERROR: ${err}`);
1829  });
1830}
1831```
1832
1833### selectOutputDevice<sup>9+</sup>
1834
1835selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
1836
1837选择音频输出设备,当前只能选择一个输出设备,使用callback方式异步返回结果。
1838
1839**系统接口:** 该接口为系统接口
1840
1841**系统能力:** SystemCapability.Multimedia.Audio.Device
1842
1843**参数:**
1844
1845| 参数名                       | 类型                                                         | 必填 | 说明                      |
1846| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
1847| outputAudioDevices          | [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors)            | 是   | 输出设备类。               |
1848| callback                    | AsyncCallback&lt;void&gt;                                    | 是   | 回调函数。当选择音频输出设备成功,err为undefined,否则为错误对象。 |
1849
1850**示例:**
1851```ts
1852import { audio } from '@kit.AudioKit';
1853import { BusinessError } from '@kit.BasicServicesKit';
1854
1855let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
1856  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
1857  deviceType : audio.DeviceType.SPEAKER,
1858  id : 1,
1859  name : "",
1860  address : "",
1861  sampleRates : [44100],
1862  channelCounts : [2],
1863  channelMasks : [0],
1864  networkId : audio.LOCAL_NETWORK_ID,
1865  interruptGroupId : 1,
1866  volumeGroupId : 1,
1867  displayName : "",
1868}];
1869
1870async function selectOutputDevice(){
1871  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err: BusinessError) => {
1872    if (err) {
1873      console.error(`Result ERROR: ${err}`);
1874    } else {
1875      console.info('Select output devices result callback: SUCCESS'); }
1876  });
1877}
1878```
1879
1880### selectOutputDevice<sup>9+</sup>
1881
1882selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
1883
1884**系统接口:** 该接口为系统接口
1885
1886选择音频输出设备,当前只能选择一个输出设备,使用Promise方式异步返回结果。
1887
1888**系统能力:** SystemCapability.Multimedia.Audio.Device
1889
1890**参数:**
1891
1892| 参数名                       | 类型                                                         | 必填 | 说明                      |
1893| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
1894| outputAudioDevices          | [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors)            | 是   | 输出设备类。               |
1895
1896**返回值:**
1897
1898| 类型                  | 说明                         |
1899| --------------------- | --------------------------- |
1900| Promise&lt;void&gt;   | Promise对象,无返回结果。 |
1901
1902**示例:**
1903
1904```ts
1905import { audio } from '@kit.AudioKit';
1906import { BusinessError } from '@kit.BasicServicesKit';
1907
1908let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
1909  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
1910  deviceType : audio.DeviceType.SPEAKER,
1911  id : 1,
1912  name : "",
1913  address : "",
1914  sampleRates : [44100],
1915  channelCounts : [2],
1916  channelMasks : [0],
1917  networkId : audio.LOCAL_NETWORK_ID,
1918  interruptGroupId : 1,
1919  volumeGroupId : 1,
1920  displayName : "",
1921}];
1922
1923async function selectOutputDevice(){
1924  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
1925    console.info('Select output devices result promise: SUCCESS');
1926  }).catch((err: BusinessError) => {
1927    console.error(`Result ERROR: ${err}`);
1928  });
1929}
1930```
1931
1932### selectOutputDeviceByFilter<sup>9+</sup>
1933
1934selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
1935
1936**系统接口:** 该接口为系统接口
1937
1938根据过滤条件,选择音频输出设备,当前只能选择一个输出设备,使用callback方式异步返回结果。
1939
1940**系统能力:** SystemCapability.Multimedia.Audio.Device
1941
1942**参数:**
1943
1944| 参数名                       | 类型                                                         | 必填 | 说明                      |
1945| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
1946| filter                      | [AudioRendererFilter](#audiorendererfilter9)                 | 是   | 过滤条件类。               |
1947| outputAudioDevices          | [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors)            | 是   | 输出设备类。               |
1948| callback                    | AsyncCallback&lt;void&gt;                                    | 是   | 回调函数。当选择音频输出设备成功,err为undefined,否则为错误对象。 |
1949
1950**示例:**
1951```ts
1952import { audio } from '@kit.AudioKit';
1953import { BusinessError } from '@kit.BasicServicesKit';
1954
1955let outputAudioRendererFilter: audio.AudioRendererFilter = {
1956  uid : 20010041,
1957  rendererInfo : {
1958    usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
1959    rendererFlags : 0
1960  },
1961  rendererId : 0
1962};
1963
1964let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
1965  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
1966  deviceType : audio.DeviceType.SPEAKER,
1967  id : 1,
1968  name : "",
1969  address : "",
1970  sampleRates : [44100],
1971  channelCounts : [2],
1972  channelMasks : [0],
1973  networkId : audio.LOCAL_NETWORK_ID,
1974  interruptGroupId : 1,
1975  volumeGroupId : 1,
1976  displayName : "",
1977}];
1978
1979async function selectOutputDeviceByFilter(){
1980  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor, (err: BusinessError) => {
1981    if (err) {
1982      console.error(`Result ERROR: ${err}`);
1983    } else {
1984      console.info('Select output devices by filter result callback: SUCCESS'); }
1985  });
1986}
1987```
1988
1989### selectOutputDeviceByFilter<sup>9+</sup>
1990
1991selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
1992
1993**系统接口:** 该接口为系统接口
1994
1995根据过滤条件,选择音频输出设备,当前只能选择一个输出设备,使用Promise方式异步返回结果。
1996
1997**系统能力:** SystemCapability.Multimedia.Audio.Device
1998
1999**参数:**
2000
2001| 参数名                 | 类型                                                         | 必填 | 说明                      |
2002| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
2003| filter                | [AudioRendererFilter](#audiorendererfilter9)                 | 是   | 过滤条件类。               |
2004| outputAudioDevices    | [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors)            | 是   | 输出设备类。               |
2005
2006**返回值:**
2007
2008| 类型                  | 说明                         |
2009| --------------------- | --------------------------- |
2010| Promise&lt;void&gt;   | Promise对象,无返回结果。 |
2011
2012**示例:**
2013
2014```ts
2015import { audio } from '@kit.AudioKit';
2016import { BusinessError } from '@kit.BasicServicesKit';
2017
2018let outputAudioRendererFilter: audio.AudioRendererFilter = {
2019  uid : 20010041,
2020  rendererInfo : {
2021    usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
2022    rendererFlags : 0
2023  },
2024  rendererId : 0
2025};
2026
2027let outputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
2028  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
2029  deviceType : audio.DeviceType.SPEAKER,
2030  id : 1,
2031  name : "",
2032  address : "",
2033  sampleRates : [44100],
2034  channelCounts : [2],
2035  channelMasks : [0],
2036  networkId : audio.LOCAL_NETWORK_ID,
2037  interruptGroupId : 1,
2038  volumeGroupId : 1,
2039  displayName : "",
2040}];
2041
2042async function selectOutputDeviceByFilter(){
2043  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor).then(() => {
2044    console.info('Select output devices by filter result promise: SUCCESS');
2045  }).catch((err: BusinessError) => {
2046    console.error(`Result ERROR: ${err}`);
2047  })
2048}
2049```
2050
2051### selectInputDeviceByFilter<sup>18+</sup>
2052
2053selectInputDeviceByFilter(filter: AudioCapturerFilter, inputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
2054
2055根据过滤条件,选择音频输入设备,当前只能选择一个输入设备。使用Promise异步回调。
2056
2057**系统接口:** 该接口为系统接口
2058
2059**系统能力:** SystemCapability.Multimedia.Audio.Device
2060
2061**参数:**
2062
2063| 参数名                 | 类型                                                                | 必填 | 说明     |
2064| ----------------------|-------------------------------------------------------------------| ---- |--------|
2065| filter                      | [AudioCapturerFilter](#audiocapturerfilter18)                     | 是   | 过滤条件类。 |
2066| inputAudioDevices | [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors) | 是   | 输入设备类。 |
2067
2068**返回值:**
2069
2070| 类型                  | 说明                         |
2071| --------------------- | --------------------------- |
2072| Promise&lt;void&gt;   | Promise对象,无返回结果。 |
2073
2074**错误码:**
2075
2076以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
2077
2078| 错误码ID | 错误信息 |
2079| ------- | --------------------------------------------|
2080| 202 | Not system App. |
2081| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2082| 6800101 |  Parameter verification failed.|
2083
2084
2085**示例:**
2086
2087```ts
2088import { audio } from '@kit.AudioKit';
2089import { BusinessError } from '@kit.BasicServicesKit';
2090
2091let inputAudioCapturerFilter: audio.AudioCapturerFilter = {
2092    uid : 20010041,
2093    capturerInfo : {
2094        source: audio.SourceType.SOURCE_TYPE_MIC,
2095        capturerFlags: 0
2096    }
2097};
2098
2099let inputAudioDeviceDescriptor: audio.AudioDeviceDescriptors = [{
2100    deviceRole : audio.DeviceRole.INPUT_DEVICE,
2101    deviceType : audio.DeviceType.MIC,
2102    id : 1,
2103    name : "",
2104    address : "",
2105    sampleRates : [44100],
2106    channelCounts : [2],
2107    channelMasks : [0],
2108    networkId : audio.LOCAL_NETWORK_ID,
2109    interruptGroupId : 1,
2110    volumeGroupId : 1,
2111    displayName : "",
2112}];
2113
2114async function selectInputDeviceByFilter(){
2115    let audioManager = audio.getAudioManager();  // 需要先创建AudioManager实例。
2116    let audioRoutingManager = audioManager.getRoutingManager();  // 再调用AudioManager的方法创建AudioRoutingManager实例。
2117    audioRoutingManager.selectInputDeviceByFilter(inputAudioCapturerFilter, inputAudioDeviceDescriptor).then(() => {
2118        console.info('Select input devices by filter result promise: SUCCESS');
2119    }).catch((err: BusinessError) => {
2120        console.error(`Result ERROR: ${err}`);
2121    })
2122}
2123```
2124
2125### getPreferredOutputDeviceByFilter<sup>18+</sup>
2126
2127getPreferredOutputDeviceByFilter(filter: AudioRendererFilter): AudioDeviceDescriptors
2128
2129根据过滤条件,查询音频输出设备。
2130
2131**系统接口:** 该接口为系统接口
2132
2133**系统能力:** SystemCapability.Multimedia.Audio.Device
2134
2135**参数:**
2136
2137| 参数名                       | 类型                                                         | 必填 | 说明                      |
2138| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
2139| filter                      | [AudioRendererFilter](#audiorendererfilter9)                 | 是   | 过滤条件类。               |
2140
2141**返回值:**
2142
2143| 类型                  | 说明                         |
2144| --------------------- | --------------------------- |
2145| [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors)| return the device list. |
2146
2147**错误码:**
2148
2149以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
2150
2151| 错误码ID | 错误信息 |
2152| ------- | --------------------------------------------|
2153| 202 | Not system App. |
2154| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2155| 6800101 |  Parameter verification failed.|
2156
2157**示例:**
2158```ts
2159import { audio } from '@kit.AudioKit';
2160import { BusinessError } from '@kit.BasicServicesKit';
2161
2162let outputAudioRendererFilter: audio.AudioRendererFilter = {
2163  uid : 20010041,
2164  rendererInfo : {
2165    usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
2166    rendererFlags : 0
2167  },
2168  rendererId : 0
2169};
2170
2171async function selectOutputDeviceByFilter(){
2172    let audioManager = audio.getAudioManager();  // 需要先创建AudioManager实例。
2173    let audioRoutingManager = audioManager.getRoutingManager();  // 再调用AudioManager的方法创建AudioRoutingManager实例。
2174    let desc : audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredOutputDeviceByFilter(outputAudioRendererFilter);
2175    console.info(`device descriptor: ${desc}`);
2176}
2177```
2178
2179### getPreferredInputDeviceByFilter<sup>18+</sup>
2180
2181getPreferredInputDeviceByFilter(filter: AudioCapturerFilter): AudioDeviceDescriptors
2182
2183根据过滤条件,查询音频输入设备,当前只能查询一个输入设备。
2184
2185**系统接口:** 该接口为系统接口
2186
2187**系统能力:** SystemCapability.Multimedia.Audio.Device
2188
2189**参数:**
2190
2191| 参数名                 | 类型                                            | 必填 | 说明                      |
2192|---------------------|-----------------------------------------------| ---- | ------------------------- |
2193| filter              | [AudioCapturerFilter](#audiocapturerfilter18) | 是   | 过滤条件类。 |
2194
2195**返回值:**
2196
2197| 类型                  | 说明                         |
2198| --------------------- | --------------------------- |
2199| [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors) | return the device list. |
2200
2201**错误码:**
2202
2203以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[Audio错误码](errorcode-audio.md)。
2204
2205| 错误码ID | 错误信息 |
2206| ------- | --------------------------------------------|
2207| 202 | Not system App. |
2208| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2209| 6800101 |  Parameter verification failed.|
2210
2211**示例:**
2212
2213```ts
2214import { audio } from '@kit.AudioKit';
2215import { BusinessError } from '@kit.BasicServicesKit';
2216
2217let inputAudioCapturerFilter: audio.AudioCapturerFilter = {
2218    uid : 20010041,
2219    capturerInfo : {
2220        source: audio.SourceType.SOURCE_TYPE_MIC,
2221        capturerFlags: 0
2222    }
2223};
2224
2225async function getPreferredInputDeviceByFilter(){
2226    let audioManager = audio.getAudioManager();  // 需要先创建AudioManager实例。
2227    let audioRoutingManager = audioManager.getRoutingManager();  // 再调用AudioManager的方法创建AudioRoutingManager实例。
2228    let desc: audio.AudioDeviceDescriptors = audioRoutingManager.getPreferredInputDeviceByFilter(inputAudioCapturerFilter);
2229    console.info(`device descriptor: ${desc}`);
2230}
2231```
2232
2233### excludeOutputDevices<sup>18+</sup>
2234
2235excludeOutputDevices(usage: DeviceUsage, devices: AudioDeviceDescriptors): Promise&lt;void&gt;
2236
2237排除输出设备。成功调用此函数后,音频将不会在指定的设备上播放。
2238
2239> **说明:**
2240>
2241> 该功能仅能排除外部输出设备,不支持本地输出设备。
2242
2243**需要权限:** ohos.permission.MANAGE_AUDIO_CONFIG
2244
2245**系统接口:** 该接口为系统接口。
2246
2247**系统能力:** SystemCapability.Multimedia.Audio.Device
2248
2249**参数:**
2250
2251| 参数名                       | 类型                                                         | 必填 | 说明                      |
2252| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
2253| usage          | [DeviceUsage](js-apis-audio.md#deviceusage12)            | 是   | 设备种类。只支持排除输出设备。               |
2254| devices          | [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors)            | 是   | 排除输出设备列表。               |
2255
2256**返回值:**
2257
2258| 类型                  | 说明                         |
2259| --------------------- | --------------------------- |
2260| Promise&lt;void&gt;   | Promise对象。无返回结果。 |
2261
2262**示例:**
2263
2264```ts
2265import { audio } from '@kit.AudioKit';
2266import { BusinessError } from '@kit.BasicServicesKit';
2267
2268let usage: audio.DeviceUsage.MEDIA_OUTPUT_DEVICES;
2269let excludedDevices: audio.AudioDeviceDescriptors = [{
2270  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
2271  deviceType : audio.DeviceType.BLUETOOTH_A2DP,
2272  id : 3,
2273  name : "",
2274  address : "",
2275  sampleRates : [44100],
2276  channelCounts : [2],
2277  channelMasks : [0],
2278  networkId : audio.LOCAL_NETWORK_ID,
2279  interruptGroupId : 1,
2280  volumeGroupId : 1,
2281  displayName : "",
2282}];
2283
2284async function excludeOutputDevices(){
2285  audioRoutingManager.excludeOutputDevices(usage, excludedDevices, (err: BusinessError) => {
2286    if (err) {
2287      console.error(`Result ERROR: ${err}`);
2288    } else {
2289      console.info('Exclude Output Devices result callback: SUCCESS'); }
2290  });
2291}
2292```
2293
2294### unexcludeOutputDevices<sup>18+</sup>
2295
2296unexcludeOutputDevices(usage: DeviceUsage, devices: AudioDeviceDescriptors): Promise&lt;void&gt;
2297
2298解除排除输出设备。成功调用此函数后,音频将会重新选择输出设备。
2299
2300**需要权限:** ohos.permission.MANAGE_AUDIO_CONFIG
2301
2302**系统接口:** 该接口为系统接口。
2303
2304**系统能力:** SystemCapability.Multimedia.Audio.Device
2305
2306**参数:**
2307
2308| 参数名                       | 类型                                                         | 必填 | 说明                      |
2309| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
2310| usage          | [DeviceUsage](js-apis-audio.md#deviceusage12)            | 是   | 设备种类。只支持排除输出设备。               |
2311| devices          | [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors)            | 是   | 解除排除输出设备列表。               |
2312
2313**返回值:**
2314
2315| 类型                  | 说明                         |
2316| --------------------- | --------------------------- |
2317| Promise&lt;void&gt;   | Promise对象。无返回结果。 |
2318
2319**示例:**
2320
2321```ts
2322import { audio } from '@kit.AudioKit';
2323import { BusinessError } from '@kit.BasicServicesKit';
2324
2325let usage: audio.DeviceUsage.MEDIA_OUTPUT_DEVICES;
2326let unexcludedDevices: audio.AudioDeviceDescriptors = [{
2327  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
2328  deviceType : audio.DeviceType.BLUETOOTH_A2DP,
2329  id : 3,
2330  name : "",
2331  address : "",
2332  sampleRates : [44100],
2333  channelCounts : [2],
2334  channelMasks : [0],
2335  networkId : audio.LOCAL_NETWORK_ID,
2336  interruptGroupId : 1,
2337  volumeGroupId : 1,
2338  displayName : "",
2339}];
2340
2341async function unexcludeOutputDevices(){
2342  audioRoutingManager.unexcludeOutputDevices(usage, unexcludedDevices, (err: BusinessError) => {
2343    if (err) {
2344      console.error(`Result ERROR: ${err}`);
2345    } else {
2346      console.info('Unexclude Output Devices result callback: SUCCESS'); }
2347  });
2348}
2349```
2350
2351### unexcludeOutputDevices<sup>18+</sup>
2352
2353unexcludeOutputDevices(usage: DeviceUsage): Promise&lt;void&gt;
2354
2355解除属于特定用途的所有输出设备的排除。成功调用此函数后,音频将会重新选择输出设备。
2356
2357**需要权限:** ohos.permission.MANAGE_AUDIO_CONFIG
2358
2359**系统接口:** 该接口为系统接口。
2360
2361**系统能力:** SystemCapability.Multimedia.Audio.Device
2362
2363**参数:**
2364
2365| 参数名                       | 类型                                                         | 必填 | 说明                      |
2366| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
2367| usage          | [DeviceUsage](js-apis-audio.md#deviceusage12)            | 是   | 设备种类。只支持排除输出设备。               |
2368
2369**返回值:**
2370
2371| 类型                  | 说明                         |
2372| --------------------- | --------------------------- |
2373| Promise&lt;void&gt;   | Promise对象。无返回结果。 |
2374
2375**示例:**
2376
2377```ts
2378import { audio } from '@kit.AudioKit';
2379import { BusinessError } from '@kit.BasicServicesKit';
2380
2381let usage: audio.DeviceUsage.MEDIA_OUTPUT_DEVICES;
2382
2383async function unexcludeOutputDevices(){
2384  audioRoutingManager.unexcludeOutputDevices(usage).then(() => {
2385    console.info('Unexclude Output Devices result promise: SUCCESS');
2386  }).catch((err: BusinessError) => {
2387    console.error(`Result ERROR: ${err}`);
2388  });
2389}
2390```
2391
2392### getExcludedDevices<sup>18+</sup>
2393
2394getExcludedDevices(usage: DeviceUsage): AudioDeviceDescriptors
2395
2396获取排除输出设备列表。
2397
2398**需要权限:** ohos.permission.MANAGE_AUDIO_CONFIG
2399
2400**系统接口:** 该接口为系统接口。
2401
2402**系统能力:** SystemCapability.Multimedia.Audio.Device
2403
2404**参数:**
2405
2406| 参数名                       | 类型                                                         | 必填 | 说明                      |
2407| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
2408| usage          | [DeviceUsage](js-apis-audio.md#deviceusage12)            | 是   | 设备种类。只支持排除输出设备。               |
2409
2410**返回值:**
2411
2412| 类型                  | 说明                         |
2413| --------------------- | --------------------------- |
2414| [AudioDeviceDescriptors](js-apis-audio.md#audiodevicedescriptors) | 排除设备列表。 |
2415
2416**示例:**
2417
2418```ts
2419import { audio } from '@kit.AudioKit';
2420
2421let usage: audio.DeviceUsage.MEDIA_OUTPUT_DEVICES;
2422
2423async function getExcludedDevices(){
2424  let desc: audio.AudioDeviceDescriptors = audioRoutingManager.getExcludedDevices(usage);
2425  console.info(`device descriptor: ${desc}`);
2426}
2427```
2428
2429## AudioRendererChangeInfo<sup>9+</sup>
2430
2431描述音频渲染器更改信息。
2432
2433**系统能力:** SystemCapability.Multimedia.Audio.Renderer
2434
2435| 名称               | 类型                                       | 可读 | 可写 | 说明                          |
2436| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
2437| clientUid          | number                                    | 是   | 否   | 音频渲染器客户端应用程序的Uid。<br/>此接口为系统接口。 |
2438| rendererState      | [AudioState](js-apis-audio.md#audiostate8)                 | 是   | 否   | 音频状态。<br/>此接口为系统接口。|
2439
2440## AudioCapturerChangeInfo<sup>9+</sup>
2441
2442描述音频采集器更改信息。
2443
2444**系统能力:** SystemCapability.Multimedia.Audio.Capturer
2445
2446| 名称               | 类型                                       | 可读 | 可写 | 说明                          |
2447| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
2448| clientUid          | number                                    | 是   | 否   | 音频采集器客户端应用程序的Uid。<br/>此接口为系统接口。 |
2449| capturerState      | [AudioState](js-apis-audio.md#audiostate8)                 | 是   | 否   | 音频状态。<br/>此接口为系统接口。|
2450
2451## AudioDeviceDescriptor
2452
2453描述音频设备。
2454
2455| 名称                          | 类型                       | 可读 | 可写 | 说明       |
2456| ----------------------------- | -------------------------- | ---- | ---- | ---------- |
2457| networkId<sup>9+</sup>        | string                     | 是   | 否   | 设备组网的ID。<br/>此接口为系统接口。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
2458| interruptGroupId<sup>9+</sup> | number                     | 是   | 否   | 设备所处的焦点组ID。<br/>此接口为系统接口。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
2459| volumeGroupId<sup>9+</sup>    | number                     | 是   | 否   | 设备所处的音量组ID。<br/>此接口为系统接口。 <br> **系统能力:** SystemCapability.Multimedia.Audio.Device|
2460
2461## AudioRendererFilter<sup>9+</sup>
2462
2463过滤条件类。在调用selectOutputDeviceByFilter接口前,需要先创建AudioRendererFilter实例。
2464
2465**系统接口:** 该接口为系统接口
2466
2467| 名称          | 类型                                     | 必填 | 说明          |
2468| -------------| ---------------------------------------- | ---- | -------------- |
2469| uid          | number                                   |  否  | 表示应用ID。<br> **系统能力:** SystemCapability.Multimedia.Audio.Core|
2470| rendererInfo | [AudioRendererInfo](js-apis-audio.md#audiorendererinfo8) |  否  | 表示渲染器信息。<br> **系统能力:** SystemCapability.Multimedia.Audio.Renderer|
2471| rendererId   | number                                   |  否  | 音频流唯一id。<br> **系统能力:** SystemCapability.Multimedia.Audio.Renderer|
2472
2473**示例:**
2474
2475```ts
2476import { audio } from '@kit.AudioKit';
2477
2478let outputAudioRendererFilter: audio.AudioRendererFilter = {
2479  uid : 20010041,
2480  rendererInfo : {
2481    usage : audio.StreamUsage.STREAM_USAGE_MUSIC,
2482    rendererFlags : 0
2483  },
2484  rendererId : 0
2485};
2486```
2487## AudioCapturerFilter<sup>18+</sup>
2488
2489过滤条件类。在调用selectOutputDeviceByFilter接口前,需要先创建AudioCapturerFilter实例。
2490
2491**系统接口:** 该接口为系统接口
2492
2493| 名称          | 类型                                     | 必填 | 说明          |
2494| -------------| ---------------------------------------- | ---- | -------------- |
2495| uid          | number                                   |  否  | 表示应用ID。<br> **系统能力:** SystemCapability.Multimedia.Audio.Core|
2496| capturerInfo | [AudioCapturerInfo](js-apis-audio.md#audiocapturerinfo8) |  否  | 表示采集器信息。。<br> **系统能力:** SystemCapability.Multimedia.Audio.Capturer|
2497
2498**示例:**
2499
2500```ts
2501import { audio } from '@kit.AudioKit';
2502
2503let inputAudioCapturerFilter: audio.AudioCapturerFilter = {
2504    uid : 20010041,
2505    capturerInfo : {
2506        source: audio.SourceType.SOURCE_TYPE_MIC,
2507        capturerFlags: 0
2508    }
2509};
2510```
2511
2512## AudioSpatialEnabledStateForDevice<sup>12+</sup>
2513
2514监听设备空间音频开关状态。
2515
2516**系统接口**:此接口为系统接口。
2517
2518**系统能力**:SystemCapability.Multimedia.Audio
2519
2520| 参数名                 | 类型                                                         | 必填 | 说明                      |
2521| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
2522| deviceDescriptor | [AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)         | 是   | 指定设备的描述。     |
2523| enabled               | boolean                                                      | 是   | 表示开启/关闭空间音频渲染或头动。true为开启,false为关闭。  |
2524
2525## AudioSpatializationManager<sup>11+</sup>
2526
2527空间音频管理。在使用AudioSpatializationManager的接口前,需要使用[getSpatializationManager](js-apis-audio.md#getspatializationmanager18)获取AudioSpatializationManager实例。
2528
2529### isSpatializationSupported<sup>11+</sup>
2530
2531isSpatializationSupported(): boolean
2532
2533获取系统是否支持空间音频,同步返回结果。
2534
2535**系统接口:** 该接口为系统接口
2536
2537**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
2538
2539**返回值:**
2540
2541| 类型                   | 说明                                                         |
2542| ---------------------- | ------------------------------------------------------------ |
2543| boolean | 返回系统是否支持空间音频,true为支持,false为不支持。 |
2544
2545**错误码:**
2546
2547以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2548
2549| 错误码ID | 错误信息 |
2550| ------- | --------------------------------------------|
2551| 202     | Not system App.                             |
2552
2553**示例:**
2554
2555```ts
2556import { audio } from '@kit.AudioKit';
2557import { BusinessError } from '@kit.BasicServicesKit';
2558try {
2559  let isSpatializationSupported: boolean = audioSpatializationManager.isSpatializationSupported();
2560  console.info(`AudioSpatializationManager isSpatializationSupported: ${isSpatializationSupported}`);
2561} catch (err) {
2562  let error = err as BusinessError;
2563  console.error(`ERROR: ${error}`);
2564}
2565```
2566
2567### isSpatializationSupportedForDevice<sup>11+</sup>
2568
2569isSpatializationSupportedForDevice(deviceDescriptor: AudioDeviceDescriptor): boolean
2570
2571获取指定设备是否支持空间音频,同步返回结果。
2572
2573**系统接口:** 该接口为系统接口
2574
2575**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
2576
2577**参数:**
2578
2579| 参数名     | 类型                                                         | 必填 | 说明                 |
2580| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
2581| deviceDescriptor | [AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)         | 是   | 指定设备的描述。     |
2582
2583**返回值:**
2584
2585| 类型                   | 说明                                                         |
2586| ---------------------- | ------------------------------------------------------------ |
2587| boolean | 返回指定设备是否支持空间音频,true为支持,false为不支持。 |
2588
2589**错误码:**
2590
2591以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2592
2593| 错误码ID | 错误信息 |
2594| ------- | --------------------------------------------|
2595| 202     | Not system App.                             |
2596| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2597| 6800101 | Parameter verification failed. |
2598
2599**示例:**
2600
2601```ts
2602import { audio } from '@kit.AudioKit';
2603import { BusinessError } from '@kit.BasicServicesKit';
2604
2605let deviceDescriptor: audio.AudioDeviceDescriptor = {
2606  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
2607  deviceType : audio.DeviceType.BLUETOOTH_A2DP,
2608  id : 1,
2609  name : "",
2610  address : "123",
2611  sampleRates : [44100],
2612  channelCounts : [2],
2613  channelMasks : [0],
2614  networkId : audio.LOCAL_NETWORK_ID,
2615  interruptGroupId : 1,
2616  volumeGroupId : 1,
2617  displayName : ""
2618};
2619
2620try {
2621  let isSpatializationSupportedForDevice: boolean = audioSpatializationManager.isSpatializationSupportedForDevice(deviceDescriptor);
2622  console.info(`AudioSpatializationManager isSpatializationSupportedForDevice: ${isSpatializationSupportedForDevice}`);
2623} catch (err) {
2624  let error = err as BusinessError;
2625  console.error(`ERROR: ${error}`);
2626}
2627```
2628
2629### isHeadTrackingSupported<sup>11+</sup>
2630
2631isHeadTrackingSupported(): boolean
2632
2633获取系统是否支持头动跟踪,同步返回结果。
2634
2635**系统接口:** 该接口为系统接口
2636
2637**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
2638
2639**返回值:**
2640
2641| 类型                   | 说明                                                         |
2642| ---------------------- | ------------------------------------------------------------ |
2643| boolean | 返回系统是否支持头动跟踪,true为支持,false为不支持。 |
2644
2645**错误码:**
2646
2647以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2648
2649| 错误码ID | 错误信息 |
2650| ------- | --------------------------------------------|
2651| 202     | Not system App.                             |
2652
2653**示例:**
2654
2655```ts
2656import { audio } from '@kit.AudioKit';
2657import { BusinessError } from '@kit.BasicServicesKit';
2658
2659try {
2660  let isHeadTrackingSupported: boolean = audioSpatializationManager.isHeadTrackingSupported();
2661  console.info(`AudioSpatializationManager isHeadTrackingSupported: ${isHeadTrackingSupported}`);
2662} catch (err) {
2663  let error = err as BusinessError;
2664  console.error(`ERROR: ${error}`);
2665}
2666```
2667
2668### isHeadTrackingSupportedForDevice<sup>11+</sup>
2669
2670isHeadTrackingSupportedForDevice(deviceDescriptor: AudioDeviceDescriptor): boolean
2671
2672获取指定设备是否支持头动跟踪,同步返回结果。
2673
2674**系统接口:** 该接口为系统接口
2675
2676**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
2677
2678**参数:**
2679
2680| 参数名     | 类型                                                         | 必填 | 说明                 |
2681| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
2682| deviceDescriptor | [AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)         | 是   | 指定设备的描述。     |
2683
2684**返回值:**
2685
2686| 类型                   | 说明                                                         |
2687| ---------------------- | ------------------------------------------------------------ |
2688| boolean | 返回指定设备是否支持头动跟踪,true为支持,false为不支持。 |
2689
2690**错误码:**
2691
2692以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2693
2694| 错误码ID | 错误信息 |
2695| ------- | --------------------------------------------|
2696| 202     | Not system App.                             |
2697| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2698| 6800101 | Parameter verification failed. |
2699
2700**示例:**
2701
2702```ts
2703import { audio } from '@kit.AudioKit';
2704import { BusinessError } from '@kit.BasicServicesKit';
2705
2706let deviceDescriptor: audio.AudioDeviceDescriptor = {
2707  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
2708  deviceType : audio.DeviceType.BLUETOOTH_A2DP,
2709  id : 1,
2710  name : "",
2711  address : "123",
2712  sampleRates : [44100],
2713  channelCounts : [2],
2714  channelMasks : [0],
2715  networkId : audio.LOCAL_NETWORK_ID,
2716  interruptGroupId : 1,
2717  volumeGroupId : 1,
2718  displayName : ""
2719};
2720
2721try {
2722  let isHeadTrackingSupportedForDevice: boolean = audioSpatializationManager.isHeadTrackingSupportedForDevice(deviceDescriptor);
2723  console.info(`AudioSpatializationManager isHeadTrackingSupportedForDevice: ${isHeadTrackingSupportedForDevice}`);
2724} catch (err) {
2725  let error = err as BusinessError;
2726  console.error(`ERROR: ${error}`);
2727}
2728```
2729
2730### setSpatializationEnabled<sup>(deprecated)</sup>
2731
2732setSpatializationEnabled(enable: boolean, callback: AsyncCallback&lt;void&gt;): void
2733
2734根据输入指令,开启/关闭空间音频渲染效果,使用callback方式异步返回结果。
2735
2736> **说明:**
2737> 从 API version 11 开始支持,从 API version 12 开始废弃,建议使用[setSpatializationEnabled(deviceDescriptor: AudioDeviceDescriptor, enabled: boolean): Promise\<void>](#setspatializationenabled12)替代。
2738
2739**需要权限:** ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
2740
2741**系统接口:** 该接口为系统接口
2742
2743**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
2744
2745**参数:**
2746
2747| 参数名                       | 类型                                                         | 必填 | 说明                      |
2748| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
2749| enable                      | boolean                                                      | 是   | 表示开启/关闭空间音频渲染。true为开启,false为关闭。  |
2750| callback                    | AsyncCallback&lt;void&gt;                                    | 是   | AsyncCallback对象,无返回结果。 |
2751
2752**错误码:**
2753
2754以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2755
2756| 错误码ID | 错误信息 |
2757| ------- | --------------------------------------------|
2758| 201     | Permission denied. Return by callback.      |
2759| 202     | Not system App.                             |
2760| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2761| 6800101 | Parameter verification failed. |
2762
2763**示例:**
2764```ts
2765import { audio } from '@kit.AudioKit';
2766import { BusinessError } from '@kit.BasicServicesKit';
2767
2768let enable: boolean = true;
2769
2770audioSpatializationManager.setSpatializationEnabled(enable, (err: BusinessError) => {
2771  if (err) {
2772    console.error(`Result ERROR: ${err}`);
2773  } else {
2774    console.info(`setSpatializationEnabled success`);
2775  }
2776});
2777```
2778
2779### setSpatializationEnabled<sup>(deprecated)</sup>
2780
2781setSpatializationEnabled(enable: boolean): Promise&lt;void&gt;
2782
2783根据输入指令,开启/关闭空间音频渲染效果,使用Promise方式异步返回结果。
2784
2785> **说明:**
2786> 从 API version 11 开始支持,从 API version 12 开始废弃,建议使用[setSpatializationEnabled(deviceDescriptor: AudioDeviceDescriptor, enabled: boolean): Promise\<void>](#setspatializationenabled12)替代。
2787
2788**需要权限:** ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
2789
2790**系统接口:** 该接口为系统接口
2791
2792**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
2793
2794**参数:**
2795
2796| 参数名                 | 类型                                                         | 必填 | 说明                      |
2797| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
2798| enable                | boolean                                                      | 是   | 表示开启/关闭空间音频渲染。true为开启,false为关闭。  |
2799
2800**返回值:**
2801
2802| 类型                  | 说明                         |
2803| --------------------- | --------------------------- |
2804| Promise&lt;void&gt;   | Promise对象,无返回结果。 |
2805
2806**错误码:**
2807
2808以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2809
2810| 错误码ID | 错误信息 |
2811| ------- | --------------------------------------------|
2812| 201     | Permission denied. Return by promise.       |
2813| 202     | Not system App.                             |
2814| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2815
2816**示例:**
2817
2818```ts
2819import { audio } from '@kit.AudioKit';
2820import { BusinessError } from '@kit.BasicServicesKit';
2821
2822let enable: boolean = true;
2823
2824audioSpatializationManager.setSpatializationEnabled(enable).then(() => {
2825  console.info(`setSpatializationEnabled success`);
2826}).catch((err: BusinessError) => {
2827  console.error(`Result ERROR: ${err}`);
2828});
2829```
2830### setSpatializationEnabled<sup>12+</sup>
2831
2832setSpatializationEnabled(deviceDescriptor: AudioDeviceDescriptor, enabled: boolean): Promise&lt;void&gt;
2833
2834根据输入指令,开启/关闭指定设备的空间音频渲染效果,使用Promise方式异步返回结果。
2835
2836**需要权限:** ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
2837
2838**系统接口:** 该接口为系统接口
2839
2840**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
2841
2842**参数:**
2843
2844| 参数名                 | 类型                                                         | 必填 | 说明                      |
2845| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
2846| deviceDescriptor | [AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)         | 是   | 指定设备的描述。     |
2847| enabled               | boolean                                                      | 是   | 表示开启/关闭空间音频渲染。true为开启,false为关闭。  |
2848
2849**返回值:**
2850
2851| 类型                  | 说明                         |
2852| --------------------- | --------------------------- |
2853| Promise&lt;void&gt;   | Promise对象,无返回结果。 |
2854
2855**错误码:**
2856
2857以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2858
2859| 错误码ID | 错误信息 |
2860| ------- | --------------------------------------------|
2861| 201     | Permission denied. Return by promise.       |
2862| 202     | Not system App.                             |
2863| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2864| 6800101 | Parameter verification failed. |
2865
2866
2867**示例:**
2868
2869```ts
2870import { audio } from '@kit.AudioKit';
2871import { BusinessError } from '@kit.BasicServicesKit';
2872
2873let deviceDescriptor: audio.AudioDeviceDescriptor = {
2874  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
2875  deviceType : audio.DeviceType.BLUETOOTH_A2DP,
2876  id : 1,
2877  name : "",
2878  address : "123",
2879  sampleRates : [44100],
2880  channelCounts : [2],
2881  channelMasks : [0],
2882  networkId : audio.LOCAL_NETWORK_ID,
2883  interruptGroupId : 1,
2884  volumeGroupId : 1,
2885  displayName : ""
2886};
2887let enabled: boolean = true;
2888
2889audioSpatializationManager.setSpatializationEnabled(deviceDescriptor, enabled).then(() => {
2890  console.info(`setSpatializationEnabled success`);
2891}).catch((err: BusinessError) => {
2892  console.error(`Result ERROR: ${err}`);
2893});
2894```
2895
2896### isSpatializationEnabled<sup>(deprecated)</sup>
2897
2898isSpatializationEnabled(): boolean
2899
2900获取空间音频渲染是否开启,同步返回结果。
2901
2902> **说明:**
2903> 从 API version 11 开始支持,从 API version 12 开始废弃,建议使用[isSpatializationEnabled(deviceDescriptor: AudioDeviceDescriptor): boolean](#isspatializationenabled12)替代。
2904
2905**系统接口:** 该接口为系统接口
2906
2907**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
2908
2909**返回值:**
2910
2911| 类型                   | 说明                                                         |
2912| ---------------------- | ------------------------------------------------------------ |
2913| boolean | 返回空间音频渲染是否开启,true为开启,false为未开启。 |
2914
2915**错误码:**
2916
2917以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2918
2919| 错误码ID | 错误信息 |
2920| ------- | --------------------------------------------|
2921| 202     | Not system App.                             |
2922
2923**示例:**
2924
2925```ts
2926import { audio } from '@kit.AudioKit';
2927import { BusinessError } from '@kit.BasicServicesKit';
2928
2929try {
2930  let isSpatializationEnabled: boolean = audioSpatializationManager.isSpatializationEnabled();
2931  console.info(`AudioSpatializationManager isSpatializationEnabled: ${isSpatializationEnabled}`);
2932} catch (err) {
2933  let error = err as BusinessError;
2934  console.error(`ERROR: ${error}`);
2935}
2936```
2937
2938### isSpatializationEnabled<sup>12+</sup>
2939
2940isSpatializationEnabled(deviceDescriptor: AudioDeviceDescriptor): boolean
2941
2942获取指定设备的空间音频渲染是否开启,同步返回结果。
2943
2944**系统接口:** 该接口为系统接口
2945
2946**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
2947
2948**参数:**
2949
2950| 参数名                 | 类型                                                         | 必填 | 说明                      |
2951| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
2952| deviceDescriptor | [AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor) | 是   | 指定设备的描述。     |
2953
2954**返回值:**
2955
2956| 类型                   | 说明                                                         |
2957| ---------------------- | ------------------------------------------------------------ |
2958| boolean | 返回指定设备的空间音频渲染是否开启,true为开启,false为未开启。 |
2959
2960**错误码:**
2961
2962以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
2963
2964| 错误码ID | 错误信息 |
2965| ------- | --------------------------------------------|
2966| 202     | Not system App.                             |
2967| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2968| 6800101 | Parameter verification failed. |
2969
2970**示例:**
2971
2972```ts
2973import { audio } from '@kit.AudioKit';
2974import { BusinessError } from '@kit.BasicServicesKit';
2975
2976let deviceDescriptor: audio.AudioDeviceDescriptor = {
2977  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
2978  deviceType : audio.DeviceType.BLUETOOTH_A2DP,
2979  id : 1,
2980  name : "",
2981  address : "123",
2982  sampleRates : [44100],
2983  channelCounts : [2],
2984  channelMasks : [0],
2985  networkId : audio.LOCAL_NETWORK_ID,
2986  interruptGroupId : 1,
2987  volumeGroupId : 1,
2988  displayName : ""
2989};
2990
2991try {
2992  let isSpatializationEnabled: boolean = audioSpatializationManager.isSpatializationEnabled(deviceDescriptor);
2993  console.info(`AudioSpatializationManager isSpatializationEnabled: ${isSpatializationEnabled}`);
2994} catch (err) {
2995  let error = err as BusinessError;
2996  console.error(`ERROR: ${error}`);
2997}
2998```
2999
3000### on('spatializationEnabledChange')<sup>(deprecated)</sup>
3001
3002on(type: 'spatializationEnabledChange', callback: Callback<boolean\>): void
3003
3004监听空间音频渲染开关状态变化事件(当空间音频渲染开关状态发生变化时触发),使用callback方式返回结果。
3005
3006> **说明:**
3007> 从 API version 11 开始支持,从 API version 12 开始废弃,建议使用[on(type: 'spatializationEnabledChangeForAnyDevice', callback: Callback<AudioSpatialEnabledStateForDevice\>): void](#onspatializationenabledchangeforanydevice12)替代。
3008
3009**系统接口:** 该接口为系统接口
3010
3011**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3012
3013**参数:**
3014
3015| 参数名   | 类型                                                 | 必填 | 说明                                           |
3016| :------- | :--------------------------------------------------- | :--- |:---------------------------------------------|
3017| type     | string                                               | 是   | 监听事件,固定为:'spatializationEnabledChange'。 |
3018| callback | Callback<boolean\> | 是   | 回调函数,返回空间音频渲染开关状态,true为打开,false为关闭。    |
3019
3020**错误码:**
3021
3022以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3023
3024| 错误码ID | 错误信息 |
3025| ------- | --------------------------------------------|
3026| 202     | Not system App.                             |
3027| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3028| 6800101 | Parameter verification failed. |
3029
3030**示例:**
3031
3032```ts
3033import { audio } from '@kit.AudioKit';
3034
3035audioSpatializationManager.on('spatializationEnabledChange', (isSpatializationEnabled: boolean) => {
3036  console.info(`isSpatializationEnabled: ${isSpatializationEnabled}`);
3037});
3038```
3039
3040### on('spatializationEnabledChangeForAnyDevice')<sup>12+</sup>
3041
3042on(type: 'spatializationEnabledChangeForAnyDevice', callback: Callback<AudioSpatialEnabledStateForDevice\>): void
3043
3044监听空间音频渲染开关状态变化事件(当空间音频渲染开关状态发生变化时触发),使用callback方式返回结果。
3045
3046**系统接口:** 该接口为系统接口
3047
3048**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3049
3050**参数:**
3051
3052| 参数名   | 类型                                                 | 必填 | 说明                                           |
3053| :------- | :--------------------------------------------------- | :--- |:---------------------------------------------|
3054| type     | string                                               | 是   | 监听事件,固定为:'spatializationEnabledChangeForAnyDevice'。 |
3055| callback | Callback\<[AudioSpatialEnabledStateForDevice](#audiospatialenabledstatefordevice12)> | 是   | Callback对象,返回设备信息和空间音频渲染开关状态。    |
3056
3057**错误码:**
3058
3059以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3060
3061| 错误码ID | 错误信息 |
3062| ------- | --------------------------------------------|
3063| 202     | Not system App.                             |
3064| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3065| 6800101 | Parameter verification failed. |
3066
3067**示例:**
3068
3069```ts
3070import { audio } from '@kit.AudioKit';
3071
3072audioSpatializationManager.on('spatializationEnabledChangeForAnyDevice', (audioSpatialEnabledStateForDevice: audio.AudioSpatialEnabledStateForDevice) => {
3073  console.info(`deviceDescriptor: ${audioSpatialEnabledStateForDevice.deviceDescriptor}`);
3074  console.info(`isSpatializationEnabled: ${audioSpatialEnabledStateForDevice.enabled}`);
3075});
3076```
3077
3078### off('spatializationEnabledChange')<sup>(deprecated)</sup>
3079
3080off(type: 'spatializationEnabledChange', callback?: Callback<boolean\>): void
3081
3082取消监听空间音频渲染开关状态变化事件,使用callback方式返回结果。
3083
3084> **说明:**
3085> 从 API version 11 开始支持,从 API version 12 开始废弃,建议使用[off(type: 'spatializationEnabledChangeForAnyDevice', callback: Callback<AudioSpatialEnabledStateForDevice\>): void](#offspatializationenabledchangeforanydevice12)替代。
3086
3087**系统接口:** 该接口为系统接口
3088
3089**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3090
3091**参数:**
3092
3093| 参数名   | 类型                                                | 必填 | 说明                                       |
3094| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
3095| type     | string                                              | 是   | 监听事件,固定为:'spatializationEnabledChange'。 |
3096| callback | Callback<boolean\> | 否   | 回调函数,返回空间音频渲染开关状态,true为打开,false为关闭。 |
3097
3098**错误码:**
3099
3100以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3101
3102| 错误码ID | 错误信息 |
3103| ------- | --------------------------------------------|
3104| 202     | Not system App.                             |
3105| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3106| 6800101 | Parameter verification failed. |
3107
3108**示例:**
3109
3110```ts
3111// 取消该事件的所有监听。
3112audioSpatializationManager.off('spatializationEnabledChange');
3113
3114// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听。
3115let spatializationEnabledChangeCallback = (isSpatializationEnabled: boolean) => {
3116  console.info(`isSpatializationEnabled: ${isSpatializationEnabled}`);
3117};
3118
3119audioSpatializationManager.on('spatializationEnabledChange', spatializationEnabledChangeCallback);
3120
3121audioSpatializationManager.off('spatializationEnabledChange', spatializationEnabledChangeCallback);
3122```
3123
3124### off('spatializationEnabledChangeForAnyDevice')<sup>12+</sup>
3125
3126off(type: 'spatializationEnabledChangeForAnyDevice', callback?: Callback<AudioSpatialEnabledStateForDevice\>): void
3127
3128取消监听空间音频渲染开关状态变化事件,使用callback方式返回结果。
3129
3130**系统接口:** 该接口为系统接口
3131
3132**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3133
3134**参数:**
3135
3136| 参数名   | 类型                                                 | 必填 | 说明                                           |
3137| :------- | :--------------------------------------------------- | :--- |:---------------------------------------------|
3138| type     | string                                               | 是   | 监听事件,固定为:'spatializationEnabledChangeForAnyDevice'。 |
3139| callback | Callback\<[AudioSpatialEnabledStateForDevice](#audiospatialenabledstatefordevice12)> | 是   | 回调函数,返回设备信息和空间音频渲染开关状态。 |
3140
3141**错误码:**
3142
3143以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3144
3145| 错误码ID | 错误信息 |
3146| ------- | --------------------------------------------|
3147| 202     | Not system App.                             |
3148| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3149| 6800101 | Parameter verification failed. |
3150
3151**示例:**
3152
3153```ts
3154import { audio } from '@kit.AudioKit';
3155
3156// 取消该事件的所有监听。
3157audioSpatializationManager.off('spatializationEnabledChangeForAnyDevice');
3158
3159// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听。
3160let spatializationEnabledChangeForAnyDeviceCallback = (audioSpatialEnabledStateForDevice: audio.AudioSpatialEnabledStateForDevice) => {
3161  console.info(`deviceDescriptor: ${audioSpatialEnabledStateForDevice.deviceDescriptor}`);
3162  console.info(`isSpatializationEnabled: ${audioSpatialEnabledStateForDevice.enabled}`);
3163};
3164
3165audioSpatializationManager.on('spatializationEnabledChangeForAnyDevice', spatializationEnabledChangeForAnyDeviceCallback);
3166
3167audioSpatializationManager.off('spatializationEnabledChangeForAnyDevice', spatializationEnabledChangeForAnyDeviceCallback);
3168```
3169
3170### setHeadTrackingEnabled<sup>(deprecated)</sup>
3171
3172setHeadTrackingEnabled(enable: boolean, callback: AsyncCallback&lt;void&gt;): void
3173
3174根据输入指令,开启/关闭头动跟踪效果,使用callback方式异步返回结果。
3175
3176> **说明:**
3177> 从 API version 11 开始支持,从 API version 12 开始废弃,建议使用[setHeadTrackingEnabled(deviceDescriptor: AudioDeviceDescriptor, enabled: boolean): Promise\<void>](#setheadtrackingenabled12)替代。
3178
3179**需要权限:** ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
3180
3181**系统接口:** 该接口为系统接口
3182
3183**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3184
3185**参数:**
3186
3187| 参数名                       | 类型                                                         | 必填 | 说明                      |
3188| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
3189| enable                      | boolean                                                      | 是   | 表示开启/关闭头动跟踪。true为开启,false为关闭。  |
3190| callback                    | AsyncCallback&lt;void&gt;                                    | 是   | AsyncCallback对象,无返回结果。 |
3191
3192**错误码:**
3193
3194以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3195
3196| 错误码ID | 错误信息 |
3197| ------- | --------------------------------------------|
3198| 201     | Permission denied. Return by callback.      |
3199| 202     | Not system App.                             |
3200| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3201| 6800101 | Parameter verification failed. |
3202
3203**示例:**
3204```ts
3205import { audio } from '@kit.AudioKit';
3206import { BusinessError } from '@kit.BasicServicesKit';
3207
3208let enable: boolean = true;
3209
3210audioSpatializationManager.setHeadTrackingEnabled(enable, (err: BusinessError) => {
3211  if (err) {
3212    console.error(`Result ERROR: ${err}`);
3213  } else {
3214    console.info(`setHeadTrackingEnabled success`);
3215  }
3216});
3217```
3218
3219### setHeadTrackingEnabled<sup>(deprecated)</sup>
3220
3221setHeadTrackingEnabled(enable: boolean): Promise&lt;void&gt;
3222
3223根据输入指令,开启/关闭头动跟踪效果,使用Promise方式异步返回结果。
3224
3225> **说明:**
3226> 从 API version 11 开始支持,从 API version 12 开始废弃,建议使用[setHeadTrackingEnabled(deviceDescriptor: AudioDeviceDescriptor, enabled: boolean): Promise\<void>](#setheadtrackingenabled12)替代。
3227
3228**需要权限:** ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
3229
3230**系统接口:** 该接口为系统接口
3231
3232**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3233
3234**参数:**
3235
3236| 参数名                 | 类型                                                         | 必填 | 说明                      |
3237| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
3238| enable                | boolean                                                      | 是   | 表示开启/关闭头动跟踪。true为开启,false为关闭。  |
3239
3240**返回值:**
3241
3242| 类型                  | 说明                         |
3243| --------------------- | --------------------------- |
3244| Promise&lt;void&gt;   | Promise对象,无返回结果。 |
3245
3246**错误码:**
3247
3248以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3249
3250| 错误码ID | 错误信息 |
3251| ------- | --------------------------------------------|
3252| 201     | Permission denied. Return by promise.       |
3253| 202     | Not system App.                             |
3254| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3255
3256**示例:**
3257
3258```ts
3259import { audio } from '@kit.AudioKit';
3260import { BusinessError } from '@kit.BasicServicesKit';
3261
3262let enable: boolean = true;
3263
3264audioSpatializationManager.setHeadTrackingEnabled(enable).then(() => {
3265  console.info(`setHeadTrackingEnabled success`);
3266}).catch((err: BusinessError) => {
3267  console.error(`Result ERROR: ${err}`);
3268});
3269```
3270
3271### setHeadTrackingEnabled<sup>12+</sup>
3272
3273setHeadTrackingEnabled(enable: boolean): Promise&lt;void&gt;
3274
3275根据输入指令,开启/关闭指定设备的头动跟踪效果,使用Promise方式异步返回结果。
3276
3277**需要权限:** ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
3278
3279**系统接口:** 该接口为系统接口
3280
3281**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3282
3283**参数:**
3284
3285| 参数名                 | 类型                                                         | 必填 | 说明                      |
3286| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
3287| deviceDescriptor | [AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)         | 是   | 指定设备的描述。     |
3288| enable                | boolean                                                      | 是   | 表示开启/关闭头动跟踪。true为开启,false为关闭。  |
3289
3290**返回值:**
3291
3292| 类型                  | 说明                         |
3293| --------------------- | --------------------------- |
3294| Promise&lt;void&gt;   | Promise对象,无返回结果。 |
3295
3296**错误码:**
3297
3298以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3299
3300| 错误码ID | 错误信息 |
3301| ------- | --------------------------------------------|
3302| 201     | Permission denied. Return by promise.       |
3303| 202     | Not system App.                             |
3304| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3305| 6800101 | Parameter verification failed. |
3306
3307**示例:**
3308
3309```ts
3310import { audio } from '@kit.AudioKit';
3311import { BusinessError } from '@kit.BasicServicesKit';
3312
3313let deviceDescriptor: audio.AudioDeviceDescriptor = {
3314  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
3315  deviceType : audio.DeviceType.BLUETOOTH_A2DP,
3316  id : 1,
3317  name : "",
3318  address : "123",
3319  sampleRates : [44100],
3320  channelCounts : [2],
3321  channelMasks : [0],
3322  networkId : audio.LOCAL_NETWORK_ID,
3323  interruptGroupId : 1,
3324  volumeGroupId : 1,
3325  displayName : ""
3326};
3327let enable: boolean = true;
3328
3329audioSpatializationManager.setHeadTrackingEnabled(deviceDescriptor, enable).then(() => {
3330  console.info(`setHeadTrackingEnabled success`);
3331}).catch((err: BusinessError) => {
3332  console.error(`Result ERROR: ${err}`);
3333});
3334```
3335
3336### isHeadTrackingEnabled<sup>(deprecated)</sup>
3337
3338isHeadTrackingEnabled(): boolean
3339
3340获取头动跟踪是否开启,同步返回结果。
3341
3342> **说明:**
3343> 从 API version 11 开始支持,从 API version 12 开始废弃,建议使用[isHeadTrackingEnabled(deviceDescriptor: AudioDeviceDescriptor): boolean](#isheadtrackingenabled12)替代。
3344
3345**系统接口:** 该接口为系统接口
3346
3347**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3348
3349**返回值:**
3350
3351| 类型                   | 说明                                                         |
3352| ---------------------- | ------------------------------------------------------------ |
3353| boolean | 返回头动跟踪是否开启,true为开启,false为未开启。 |
3354
3355**错误码:**
3356
3357以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3358
3359| 错误码ID | 错误信息 |
3360| ------- | --------------------------------------------|
3361| 202     | Not system App.                             |
3362
3363**示例:**
3364
3365```ts
3366import { audio } from '@kit.AudioKit';
3367import { BusinessError } from '@kit.BasicServicesKit';
3368
3369try {
3370  let isHeadTrackingEnabled: boolean = audioSpatializationManager.isHeadTrackingEnabled();
3371  console.info(`AudioSpatializationManager isHeadTrackingEnabled: ${isHeadTrackingEnabled}`);
3372} catch (err) {
3373  let error = err as BusinessError;
3374  console.error(`ERROR: ${error}`);
3375}
3376```
3377
3378### isHeadTrackingEnabled<sup>12+</sup>
3379
3380isHeadTrackingEnabled(): boolean
3381
3382获取指定设备的头动跟踪是否开启,同步返回结果。
3383
3384**系统接口:** 该接口为系统接口
3385
3386**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3387
3388**参数:**
3389
3390| 参数名                 | 类型                                                         | 必填 | 说明                      |
3391| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
3392| deviceDescriptor | [AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor) | 是   | 指定设备的描述。     |
3393
3394**返回值:**
3395
3396| 类型                   | 说明                                                         |
3397| ---------------------- | ------------------------------------------------------------ |
3398| boolean | 返回指定设备的头动跟踪是否开启,true为开启,false为未开启。 |
3399
3400**错误码:**
3401
3402以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3403
3404| 错误码ID | 错误信息 |
3405| ------- | --------------------------------------------|
3406| 202     | Not system App.                             |
3407| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3408| 6800101 | Parameter verification failed. |
3409
3410**示例:**
3411
3412```ts
3413import { audio } from '@kit.AudioKit';
3414import { BusinessError } from '@kit.BasicServicesKit';
3415
3416let deviceDescriptor: audio.AudioDeviceDescriptor = {
3417  deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
3418  deviceType : audio.DeviceType.BLUETOOTH_A2DP,
3419  id : 1,
3420  name : "",
3421  address : "123",
3422  sampleRates : [44100],
3423  channelCounts : [2],
3424  channelMasks : [0],
3425  networkId : audio.LOCAL_NETWORK_ID,
3426  interruptGroupId : 1,
3427  volumeGroupId : 1,
3428  displayName : ""
3429};
3430
3431try {
3432  let isHeadTrackingEnabled: boolean = audioSpatializationManager.isHeadTrackingEnabled(deviceDescriptor);
3433  console.info(`AudioSpatializationManager isHeadTrackingEnabled: ${isHeadTrackingEnabled}`);
3434} catch (err) {
3435  let error = err as BusinessError;
3436  console.error(`ERROR: ${error}`);
3437}
3438```
3439
3440### on('headTrackingEnabledChange')<sup>(deprecated)</sup>
3441
3442on(type: 'headTrackingEnabledChange', callback: Callback<boolean\>): void
3443
3444监听头动跟踪开关状态变化事件(当动跟踪开关状态发生变化时触发),使用callback方式返回结果。
3445
3446> **说明:**
3447> 从 API version 11 开始支持,从 API version 12 开始废弃,建议使用[on(type: 'headTrackingEnabledChangeForAnyDevice', callback: Callback<AudioSpatialEnabledStateForDevice\>): void](#onheadtrackingenabledchangeforanydevice12)替代。
3448
3449**系统接口:** 该接口为系统接口
3450
3451**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3452
3453**参数:**
3454
3455| 参数名   | 类型                                                 | 必填 | 说明                                       |
3456| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
3457| type     | string                                               | 是   | 监听事件,固定为:'headTrackingEnabledChange'。 |
3458| callback | Callback<boolean\> | 是   | Callback对象,返回头动跟踪开关状态,true为打开,false为关闭。 |
3459
3460**错误码:**
3461
3462以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3463
3464| 错误码ID | 错误信息 |
3465| ------- | --------------------------------------------|
3466| 202     | Not system App.                             |
3467| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3468| 6800101 | Parameter verification failed. |
3469
3470**示例:**
3471
3472```ts
3473import { audio } from '@kit.AudioKit';
3474
3475audioSpatializationManager.on('headTrackingEnabledChange', (isHeadTrackingEnabled: boolean) => {
3476  console.info(`isHeadTrackingEnabled: ${isHeadTrackingEnabled}`);
3477});
3478```
3479
3480### on('headTrackingEnabledChangeForAnyDevice')<sup>12+</sup>
3481
3482on(type: 'headTrackingEnabledChangeForAnyDevice', callback: Callback<AudioSpatialEnabledStateForDevice\>): void
3483
3484监听头动跟踪开关状态变化事件(当动跟踪开关状态发生变化时触发),使用callback方式返回结果。
3485
3486**系统接口:** 该接口为系统接口
3487
3488**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3489
3490**参数:**
3491
3492| 参数名   | 类型                                                 | 必填 | 说明                                       |
3493| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
3494| type     | string                                               | 是   | 监听事件,固定为:'headTrackingEnabledChangeForAnyDevice'。 |
3495| callback | Callback\<[AudioSpatialEnabledStateForDevice](#audiospatialenabledstatefordevice12)> | 是   | Callback对象,返回设备信息和空间音频头动开关状态。    |
3496
3497**错误码:**
3498
3499以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3500
3501| 错误码ID | 错误信息 |
3502| ------- | --------------------------------------------|
3503| 202     | Not system App.                             |
3504| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3505| 6800101 | Parameter verification failed. |
3506
3507**示例:**
3508
3509```ts
3510import { audio } from '@kit.AudioKit';
3511
3512audioSpatializationManager.on('headTrackingEnabledChangeForAnyDevice', (audioSpatialEnabledStateForDevice: audio.AudioSpatialEnabledStateForDevice) => {
3513  console.info(`deviceDescriptor: ${audioSpatialEnabledStateForDevice.deviceDescriptor}`);
3514  console.info(`isSpatializationEnabled: ${audioSpatialEnabledStateForDevice.enabled}`);
3515});
3516```
3517
3518### off('headTrackingEnabledChange')<sup>(deprecated)</sup>
3519
3520off(type: 'headTrackingEnabledChange', callback?: Callback<boolean\>): void
3521
3522取消监听头动跟踪开关状态变化事件,使用callback方式返回结果。
3523
3524> **说明:**
3525> 从 API version 11 开始支持,从 API version 12 开始废弃,建议使用[off(type: 'headTrackingEnabledChangeForAnyDevice', callback: Callback<AudioSpatialEnabledStateForDevice\>): void](#offheadtrackingenabledchangeforanydevice12)替代。
3526
3527**系统接口:** 该接口为系统接口
3528
3529**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3530
3531**参数:**
3532
3533| 参数名   | 类型                                                | 必填 | 说明                                       |
3534| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
3535| type     | string                                              | 是   | 监听事件,固定为:'headTrackingEnabledChange'。 |
3536| callback | Callback<boolean\> | 否   | 回调函数,返回头动跟踪开关状态,true为打开,false为关闭。 |
3537
3538**错误码:**
3539
3540以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3541
3542| 错误码ID | 错误信息 |
3543| ------- | --------------------------------------------|
3544| 202     | Not system App.                             |
3545| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3546| 6800101 | Parameter verification failed. |
3547
3548**示例:**
3549
3550```ts
3551import { audio } from '@kit.AudioKit';
3552
3553// 取消该事件的所有监听。
3554audioSpatializationManager.off('headTrackingEnabledChange');
3555
3556// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听。
3557let headTrackingEnabledChangeCallback = (isHeadTrackingEnabled: boolean) => {
3558  console.info(`isHeadTrackingEnabled: ${isHeadTrackingEnabled}`);
3559};
3560
3561audioSpatializationManager.on('headTrackingEnabledChange', headTrackingEnabledChangeCallback);
3562
3563audioSpatializationManager.off('headTrackingEnabledChange', headTrackingEnabledChangeCallback);
3564```
3565
3566### off('headTrackingEnabledChangeForAnyDevice')<sup>12+</sup>
3567
3568off(type: 'headTrackingEnabledChangeForAnyDevice', callback?: Callback<AudioSpatialEnabledStateForDevice\>): void
3569
3570取消监听头动跟踪开关状态变化事件,使用callback方式返回结果。
3571
3572**系统接口:** 该接口为系统接口
3573
3574**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3575
3576**参数:**
3577
3578| 参数名   | 类型                                                | 必填 | 说明                                       |
3579| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
3580| type     | string                                              | 是   | 监听事件,固定为:'headTrackingEnabledChangeForAnyDevice'。 |
3581| callback | Callback\<[AudioSpatialEnabledStateForDevice](#audiospatialenabledstatefordevice12)> | 是   | 回调函数,返回设备信息和空间音频头动开关状态。 |
3582
3583**错误码:**
3584
3585以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3586
3587| 错误码ID | 错误信息 |
3588| ------- | --------------------------------------------|
3589| 202     | Not system App.                             |
3590| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3591| 6800101 | Parameter verification failed. |
3592
3593**示例:**
3594
3595```ts
3596import { audio } from '@kit.AudioKit';
3597
3598// 取消该事件的所有监听。
3599audioSpatializationManager.off('headTrackingEnabledChangeForAnyDevice');
3600
3601// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听。
3602let headTrackingEnabledChangeForAnyDeviceCallback = (audioSpatialEnabledStateForDevice: audio.AudioSpatialEnabledStateForDevice) => {
3603  console.info(`deviceDescriptor: ${audioSpatialEnabledStateForDevice.deviceDescriptor}`);
3604  console.info(`isSpatializationEnabled: ${audioSpatialEnabledStateForDevice.enabled}`);
3605};
3606
3607audioSpatializationManager.on('headTrackingEnabledChangeForAnyDevice', headTrackingEnabledChangeForAnyDeviceCallback);
3608
3609audioSpatializationManager.off('headTrackingEnabledChangeForAnyDevice', headTrackingEnabledChangeForAnyDeviceCallback);
3610```
3611
3612### updateSpatialDeviceState<sup>11+</sup>
3613
3614updateSpatialDeviceState(spatialDeviceState: AudioSpatialDeviceState): void
3615
3616更新空间化设备状态,同步返回结果。
3617
3618**需要权限:** ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
3619
3620**系统接口:** 该接口为系统接口
3621
3622**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3623
3624**参数:**
3625
3626| 参数名   | 类型                                                | 必填 | 说明                                       |
3627| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
3628| spatialDeviceState     | [AudioSpatialDeviceState](#audiospatialdevicestate11)     | 是   | 需要更新的空间化设备状态。 |
3629
3630**错误码:**
3631
3632以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3633
3634| 错误码ID | 错误信息 |
3635| ------- | --------------------------------------------|
3636| 201     | Permission denied.                          |
3637| 202     | Not system App.                             |
3638| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3639| 6800101 | Parameter verification failed. |
3640
3641**示例:**
3642
3643```ts
3644import { audio } from '@kit.AudioKit';
3645import { BusinessError } from '@kit.BasicServicesKit';
3646
3647let spatialDeviceState: audio.AudioSpatialDeviceState = {
3648  address: "123",
3649  isSpatializationSupported: true,
3650  isHeadTrackingSupported: true,
3651  spatialDeviceType: audio.AudioSpatialDeviceType.SPATIAL_DEVICE_TYPE_IN_EAR_HEADPHONE
3652};
3653
3654try {
3655  audioSpatializationManager.updateSpatialDeviceState(spatialDeviceState);
3656  console.info(`AudioSpatializationManager updateSpatialDeviceState success`);
3657} catch (err) {
3658  let error = err as BusinessError;
3659  console.error(`ERROR: ${error}`);
3660}
3661```
3662
3663### setSpatializationSceneType<sup>12+</sup>
3664
3665setSpatializationSceneType(spatializationSceneType: AudioSpatializationSceneType): void
3666
3667设置空间音频渲染场景类型,同步返回结果。
3668
3669**需要权限:** ohos.permission.MANAGE_SYSTEM_AUDIO_EFFECTS
3670
3671**系统接口:** 该接口为系统接口
3672
3673**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3674
3675**参数:**
3676
3677| 参数名   | 类型                                                | 必填 | 说明                                       |
3678| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
3679| spatializationSceneType     | [AudioSpatializationSceneType](#audiospatializationscenetype12)     | 是   | 需要设置的空间音频渲染场景类型。 |
3680
3681**错误码:**
3682
3683以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3684
3685| 错误码ID | 错误信息 |
3686| ------- | --------------------------------------------|
3687| 201     | Permission denied.                          |
3688| 202     | Not system App.                             |
3689| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3690| 6800101 | Parameter verification failed. |
3691
3692**示例:**
3693
3694```ts
3695import { audio } from '@kit.AudioKit';
3696import { BusinessError } from '@kit.BasicServicesKit';
3697
3698try {
3699  audioSpatializationManager.setSpatializationSceneType(audio.AudioSpatializationSceneType.DEFAULT);
3700  console.info(`AudioSpatializationManager setSpatializationSceneType success`);
3701} catch (err) {
3702  let error = err as BusinessError;
3703  console.error(`ERROR: ${error}`);
3704}
3705```
3706
3707### getSpatializationSceneType<sup>12+</sup>
3708
3709getSpatializationSceneType(): AudioSpatializationSceneType
3710
3711查询当前空间音频渲染场景类型,同步返回结果。
3712
3713**系统接口:** 该接口为系统接口
3714
3715**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3716
3717**返回值:**
3718
3719| 类型                   | 说明                                                         |
3720| ---------------------- | ------------------------------------------------------------ |
3721| [AudioSpatializationSceneType](#audiospatializationscenetype12) | 返回当前空间音频渲染场景类型。 |
3722
3723**错误码:**
3724
3725以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
3726
3727| 错误码ID | 错误信息 |
3728| ------- | --------------------------------------------|
3729| 202     | Not system App.                             |
3730
3731**示例:**
3732
3733```ts
3734import { audio } from '@kit.AudioKit';
3735import { BusinessError } from '@kit.BasicServicesKit';
3736
3737try {
3738  let spatializationSceneType: audio.AudioSpatializationSceneType = audioSpatializationManager.getSpatializationSceneType();
3739  console.info(`AudioSpatializationManager spatializationSceneType: ${spatializationSceneType}`);
3740} catch (err) {
3741  let error = err as BusinessError;
3742  console.error(`ERROR: ${error}`);
3743}
3744```
3745
3746## AudioSpatialDeviceState<sup>11+</sup>
3747
3748空间化设备状态。
3749
3750**系统接口:** 该接口为系统接口
3751
3752**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3753
3754| 名称                          | 类型                       | 可读 | 可写 | 说明       |
3755| ----------------------------- | -------------------------- | ---- | ---- | ---------- |
3756| address | string         | 是   | 是   | 空间化设备地址。|
3757| isSpatializationSupported | boolean        | 是   | 是   | 空间化设备是否支持空间音频渲染。true表示支持,false表示不支持。|
3758| isHeadTrackingSupported | boolean        | 是   | 是   | 空间化设备是否支持头动跟踪。true表示支持,false表示不支持。|
3759| spatialDeviceType | [AudioSpatialDeviceType](#audiospatialdevicetype11)   | 是   | 是   | 空间化设备类型。|
3760
3761**示例:**
3762
3763```ts
3764import { audio } from '@kit.AudioKit';
3765
3766let spatialDeviceState: audio.AudioSpatialDeviceState = {
3767  address: "123",
3768  isSpatializationSupported: true,
3769  isHeadTrackingSupported: true,
3770  spatialDeviceType: audio.AudioSpatialDeviceType.SPATIAL_DEVICE_TYPE_IN_EAR_HEADPHONE
3771};
3772```
3773
3774## AudioSpatialDeviceType<sup>11+</sup>
3775
3776枚举,空间化设备类型。
3777
3778**系统接口:** 该接口为系统接口
3779
3780**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3781
3782| 名称                               |  值     | 说明                       |
3783| ---------------------------------- | ------ | ------------------------- |
3784| SPATIAL_DEVICE_TYPE_NONE                   | 0      |  无空间化设备类型。  |
3785| SPATIAL_DEVICE_TYPE_IN_EAR_HEADPHONE       | 1      |  入耳式耳机。       |
3786| SPATIAL_DEVICE_TYPE_HALF_IN_EAR_HEADPHONE  | 2      |  半入耳式耳机。     |
3787| SPATIAL_DEVICE_TYPE_OVER_EAR_HEADPHONE     | 3      |  头戴式耳机。       |
3788| SPATIAL_DEVICE_TYPE_GLASSES                | 4      |  眼镜式耳机。       |
3789| SPATIAL_DEVICE_TYPE_OTHERS                 | 5      |  其他空间化设备类型。|
3790
3791## AudioSpatializationSceneType<sup>12+</sup>
3792
3793枚举,空间音频渲染场景类型。
3794
3795**系统接口:** 该接口为系统接口
3796
3797**系统能力:** SystemCapability.Multimedia.Audio.Spatialization
3798
3799| 名称                               |  值     | 说明                       |
3800| ---------------------------------- | ------ | ------------------------- |
3801| DEFAULT                            | 0      |  空间音频默认渲染场景。            |
3802| MUSIC                              | 1      |  空间音频音乐渲染场景。            |
3803| MOVIE                              | 2      |  空间音频电影渲染场景。            |
3804| AUDIOBOOK                          | 3      |  空间音频有声读物渲染场景。          |
3805
3806## ToneType<sup>9+</sup>
3807
3808枚举,播放器的音调类型。
3809
3810**系统接口:** 该接口为系统接口
3811
3812**系统能力:** SystemCapability.Multimedia.Audio.Tone
3813
3814| 名称                                              |  值    | 说明                          |
3815| :------------------------------------------------ | :----- | :----------------------------|
3816| TONE_TYPE_DIAL_0                                  | 0      | 键0的DTMF音。                 |
3817| TONE_TYPE_DIAL_1                                  | 1      | 键1的DTMF音。                 |
3818| TONE_TYPE_DIAL_2                                  | 2      | 键2的DTMF音。                 |
3819| TONE_TYPE_DIAL_3                                  | 3      | 键3的DTMF音。                 |
3820| TONE_TYPE_DIAL_4                                  | 4      | 键4的DTMF音。                 |
3821| TONE_TYPE_DIAL_5                                  | 5      | 键5的DTMF音。                 |
3822| TONE_TYPE_DIAL_6                                  | 6      | 键6的DTMF音。                 |
3823| TONE_TYPE_DIAL_7                                  | 7      | 键7的DTMF音。                 |
3824| TONE_TYPE_DIAL_8                                  | 8      | 键8的DTMF音。                 |
3825| TONE_TYPE_DIAL_9                                  | 9      | 键9的DTMF音。                 |
3826| TONE_TYPE_DIAL_S                                  | 10     | 键*的DTMF音。                 |
3827| TONE_TYPE_DIAL_P                                  | 11     | 键#的DTMF音。                 |
3828| TONE_TYPE_DIAL_A                                  | 12     | 键A的DTMF音。                 |
3829| TONE_TYPE_DIAL_B                                  | 13     | 键B的DTMF音。                 |
3830| TONE_TYPE_DIAL_C                                  | 14     | 键C的DTMF音。                 |
3831| TONE_TYPE_DIAL_D                                  | 15     | 键D的DTMF音。                 |
3832| TONE_TYPE_COMMON_SUPERVISORY_DIAL                 | 100    | 呼叫监管音调,拨号音。          |
3833| TONE_TYPE_COMMON_SUPERVISORY_BUSY                 | 101    | 呼叫监管音调,忙。              |
3834| TONE_TYPE_COMMON_SUPERVISORY_CONGESTION           | 102    | 呼叫监管音调,拥塞。            |
3835| TONE_TYPE_COMMON_SUPERVISORY_RADIO_ACK            | 103    | 呼叫监管音调,无线电 ACK。      |
3836| TONE_TYPE_COMMON_SUPERVISORY_RADIO_NOT_AVAILABLE  | 104    | 呼叫监管音调,无线电不可用。     |
3837| TONE_TYPE_COMMON_SUPERVISORY_CALL_WAITING         | 106    | 呼叫监管音调,呼叫等待。        |
3838| TONE_TYPE_COMMON_SUPERVISORY_RINGTONE             | 107    | 呼叫监管音调,铃声。            |
3839| TONE_TYPE_COMMON_SUPERVISORY_CALL_HOLDING<sup>18+</sup>  | 108  | 呼叫保持音调。            |
3840| TONE_TYPE_COMMON_PROPRIETARY_BEEP                 | 200    | 专有声调,一般蜂鸣声。          |
3841| TONE_TYPE_COMMON_PROPRIETARY_ACK                  | 201    | 专有声调,ACK。                |
3842| TONE_TYPE_COMMON_PROPRIETARY_PROMPT               | 203    | 专有声调,PROMPT。             |
3843| TONE_TYPE_COMMON_PROPRIETARY_DOUBLE_BEEP          | 204    | 专有声调,双重蜂鸣声。          |
3844
3845## TonePlayer<sup>9+</sup>
3846
3847提供播放和管理DTMF(Dual Tone Multi Frequency,双音多频)音调的方法,包括各种系统监听音调、专有音调,如拨号音、通话回铃音等。
3848在调用TonePlayer的接口前,需要先通过[createTonePlayer](#audiocreatetoneplayer9)创建实例。
3849
3850**系统接口:** 该接口为系统接口
3851
3852### load<sup>9+</sup>
3853
3854load(type: ToneType, callback: AsyncCallback&lt;void&gt;): void
3855
3856加载DTMF音调配置。使用callback方式异步返回结果。
3857
3858**系统接口:** 该接口为系统接口
3859
3860**系统能力:** SystemCapability.Multimedia.Audio.Tone
3861
3862**参数:**
3863
3864| 参数名          | 类型                        | 必填  | 说明                            |
3865| :--------------| :-------------------------- | :-----| :------------------------------ |
3866| type           | [ToneType](#tonetype9)       | 是    | 配置的音调类型。                 |
3867| callback       | AsyncCallback<void\>        | 是    | 回调函数。当加载DTMF音调配置成功,err为undefined,否则为错误对象。 |
3868
3869**示例:**
3870
3871```ts
3872import { BusinessError } from '@kit.BasicServicesKit';
3873
3874tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err: BusinessError) => {
3875  if (err) {
3876    console.error(`callback call load failed error: ${err.message}`);
3877    return;
3878  } else {
3879    console.info('callback call load success');
3880  }
3881});
3882```
3883
3884### load<sup>9+</sup>
3885
3886load(type: ToneType): Promise&lt;void&gt;
3887
3888加载DTMF音调配置。使用Promise方式异步返回结果。
3889
3890**系统接口:** 该接口为系统接口
3891
3892**系统能力:** SystemCapability.Multimedia.Audio.Tone
3893
3894**参数:**
3895
3896| 参数名         | 类型                    | 必填  |  说明             |
3897| :------------- | :--------------------- | :---  | ---------------- |
3898| type           | [ToneType](#tonetype9)   | 是    | 配置的音调类型。  |
3899
3900**返回值:**
3901
3902| 类型            | 说明                        |
3903| :--------------| :-------------------------- |
3904| Promise<void\> | Promise对象,无返回结果。 |
3905
3906**示例:**
3907
3908```ts
3909tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
3910  console.info('promise call load ');
3911}).catch(() => {
3912  console.error('promise call load fail');
3913});
3914```
3915
3916### start<sup>9+</sup>
3917
3918start(callback: AsyncCallback&lt;void&gt;): void
3919
3920启动DTMF音调播放。使用callback方式异步返回结果。
3921
3922**系统接口:** 该接口为系统接口
3923
3924**系统能力:** SystemCapability.Multimedia.Audio.Tone
3925
3926**参数:**
3927
3928| 参数名   | 类型                 | 必填 | 说明                           |
3929| :------- | :------------------- | :--- | :----------------------------- |
3930| callback | AsyncCallback<void\> | 是   | 回调函数。当启动DTMF音调播放成功,err为undefined,否则为错误对象。 |
3931
3932**示例:**
3933
3934```ts
3935import { BusinessError } from '@kit.BasicServicesKit';
3936
3937tonePlayer.start((err: BusinessError) => {
3938  if (err) {
3939    console.error(`callback call start failed error: ${err.message}`);
3940    return;
3941  } else {
3942    console.info('callback call start success');
3943  }
3944});
3945```
3946
3947### start<sup>9+</sup>
3948
3949start(): Promise&lt;void&gt;
3950
3951启动DTMF音调播放。使用Promise方式异步返回结果。
3952
3953**系统接口:** 该接口为系统接口
3954
3955**系统能力:** SystemCapability.Multimedia.Audio.Tone
3956
3957**返回值:**
3958
3959| 类型           | 说明                          |
3960| :------------- | :---------------------------- |
3961| Promise<void\> | Promise对象,无返回结果。 |
3962
3963**示例:**
3964
3965```ts
3966tonePlayer.start().then(() => {
3967  console.info('promise call start');
3968}).catch(() => {
3969  console.error('promise call start fail');
3970});
3971```
3972
3973### stop<sup>9+</sup>
3974
3975stop(callback: AsyncCallback&lt;void&gt;): void
3976
3977停止当前正在播放的音调。使用callback方式异步返回结果。
3978
3979**系统接口:** 该接口为系统接口
3980
3981**系统能力:** SystemCapability.Multimedia.Audio.Tone
3982
3983**参数:**
3984
3985| 参数名   | 类型                 | 必填 | 说明                           |
3986| :------- | :------------------- | :--- | :----------------------------- |
3987| callback | AsyncCallback<void\> | 是   | 回调函数。当停止当前正在播放的音调成功,err为undefined,否则为错误对象。 |
3988
3989**示例:**
3990
3991```ts
3992import { BusinessError } from '@kit.BasicServicesKit';
3993
3994tonePlayer.stop((err: BusinessError) => {
3995  if (err) {
3996    console.error(`callback call stop error: ${err.message}`);
3997    return;
3998  } else {
3999    console.error('callback call stop success ');
4000  }
4001});
4002```
4003
4004### stop<sup>9+</sup>
4005
4006stop(): Promise&lt;void&gt;
4007
4008停止当前正在播放的音调。使用Promise方式异步返回结果。
4009
4010**系统接口:** 该接口为系统接口
4011
4012**系统能力:** SystemCapability.Multimedia.Audio.Tone
4013
4014**返回值:**
4015
4016| 类型           | 说明                          |
4017| :------------- | :---------------------------- |
4018| Promise<void\> | Promise对象,无返回结果。 |
4019
4020**示例:**
4021
4022```ts
4023tonePlayer.stop().then(() => {
4024  console.info('promise call stop finish');
4025}).catch(() => {
4026  console.error('promise call stop fail');
4027});
4028```
4029
4030### release<sup>9+</sup>
4031
4032release(callback: AsyncCallback&lt;void&gt;): void
4033
4034释放与此TonePlayer对象关联的资源。使用callback方式异步返回结果。
4035
4036**系统接口:** 该接口为系统接口
4037
4038**系统能力:** SystemCapability.Multimedia.Audio.Tone
4039
4040**参数:**
4041
4042| 参数名   | 类型                 | 必填 | 说明                            |
4043| :------- | :------------------- | :--- | :---------------------------- |
4044| callback | AsyncCallback<void\> | 是   | 回调函数。当释放与此TonePlayer对象关联的资源成功,err为undefined,否则为错误对象。 |
4045
4046**示例:**
4047
4048```ts
4049import { BusinessError } from '@kit.BasicServicesKit';
4050
4051tonePlayer.release((err: BusinessError) => {
4052  if (err) {
4053    console.error(`callback call release failed error: ${err.message}`);
4054    return;
4055  } else {
4056    console.info('callback call release success ');
4057  }
4058});
4059```
4060
4061### release<sup>9+</sup>
4062
4063release(): Promise&lt;void&gt;
4064
4065释放与此TonePlayer对象关联的资源。使用Promise方式异步返回结果。
4066
4067**系统接口:** 该接口为系统接口
4068
4069**系统能力:** SystemCapability.Multimedia.Audio.Tone
4070
4071**返回值:**
4072
4073| 类型           | 说明                          |
4074| :------------- | :---------------------------- |
4075| Promise<void\> | Promise对象,无返回结果。 |
4076
4077**示例:**
4078
4079```ts
4080tonePlayer.release().then(() => {
4081  console.info('promise call release');
4082}).catch(() => {
4083  console.error('promise call release fail');
4084});
4085```
4086
4087## AsrProcessingController<sup>12+</sup>
4088
4089ASR处理控制器
4090
4091**系统接口:** 该接口为系统接口
4092
4093**系统能力:** SystemCapability.Multimedia.Audio.Capturer
4094
4095### setAsrAecMode<sup>12+</sup>
4096
4097setAsrAecMode(mode: AsrAecMode): boolean;
4098
4099设置ASR AEC模式,同步返回结果。
4100
4101**系统接口:** 该接口为系统接口
4102
4103**系统能力:** SystemCapability.Multimedia.Audio.Capturer
4104
4105**参数:**
4106
4107| 参数名| 类型                         | 必填 | 说明 |
4108|-------|----------------------------|-------|-------|
4109| mode | [AsrAecMode](#asraecmode12) | 是 |ASR AEC 模式。 |
4110
4111**返回值:**
4112
4113| 类型 | 说明                                    |
4114|-------|---------------------------------------|
4115| boolean | 返回设置ASR AEC模式结果,true为设置成功,false为设置失败。 |
4116
4117**错误码:**
4118
4119以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4120
4121| 错误码ID   | 错误信息                                     |
4122|---------|------------------------------------------|
4123| 202 | Caller is not a system application. |
4124| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4125| 6800101 | Parameter verification failed. |
4126| 6800104 | Operation not allowed. |
4127
4128**示例:**
4129
4130```ts
4131let flag = asrProcessingController.setAsrAecMode(audio.AsrAecMode.BYPASS);
4132```
4133
4134### getAsrAecMode<sup>12+</sup>
4135
4136getAsrAecMode(): AsrAecMode;
4137
4138获取ASR AEC模式,同步返回结果。
4139
4140**系统接口:** 该接口为系统接口
4141
4142**系统能力:** SystemCapability.Multimedia.Audio.Capturer
4143
4144**返回值:**
4145
4146| 类型 | 说明 |
4147|-------|-------|
4148| [AsrAecMode](#asraecmode12) |ASR AEC 模式 |
4149
4150**错误码:**
4151
4152以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4153
4154| 错误码ID   | 错误信息                                     |
4155|---------|------------------------------------------|
4156| 202 | Caller is not a system application. |
4157| 6800104 | Operation not allowed. |
4158
4159
4160**示例:**
4161
4162```ts
4163let mode = asrProcessingController.getAsrAecMode();
4164```
4165
4166### setAsrNoiseSuppressionMode<sup>12+</sup>
4167
4168setAsrNoiseSuppressionMode(mode: AsrNoiseSuppressionMode): boolean;
4169
4170设置ASR 噪音抑制模式,同步返回结果。
4171
4172**系统接口:** 该接口为系统接口
4173
4174**系统能力:** SystemCapability.Multimedia.Audio.Capturer
4175
4176**参数:**
4177
4178| 参数名| 类型                                                    | 必填 | 说明 |
4179|-------|-------------------------------------------------------|-------|-------|
4180| mode | [AsrNoiseSuppressionMode](#asrnoisesuppressionmode12) | 是 |ASR 噪音抑制模式。 |
4181
4182**返回值:**
4183
4184| 类型 | 说明                                     |
4185|-------|----------------------------------------|
4186| boolean | 返回设置ASR 噪音抑制模式结果,true为设置成功,false为设置失败。 |
4187
4188**错误码:**
4189
4190以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4191
4192| 错误码ID   | 错误信息                                     |
4193|---------|------------------------------------------|
4194| 202 | Caller is not a system application. |
4195| 401     | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
4196| 6800101 | Parameter verification failed. |
4197| 6800104 | Operation not allowed. |
4198
4199**示例:**
4200
4201```ts
4202let flag = asrProcessingController.setAsrNoiseSuppressionMode(audio.AsrNoiseSuppressionMode.BYPASS);
4203```
4204
4205### getAsrNoiseSuppressionMode<sup>12+</sup>
4206
4207getAsrNoiseSuppressionMode(): AsrNoiseSuppressionMode;
4208
4209获取ASR 噪音抑制模式,同步返回结果。
4210
4211**系统接口:** 该接口为系统接口
4212
4213**系统能力:** SystemCapability.Multimedia.Audio.Capturer
4214
4215**返回值:**
4216
4217| 类型                      |说明 |
4218|-------------------------|-------|
4219| [AsrNoiseSuppressionMode](#asrnoisesuppressionmode12) |ASR 噪音抑制模式 |
4220
4221**错误码:**
4222
4223以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4224
4225| 错误码ID   | 错误信息                                     |
4226|---------|------------------------------------------|
4227| 202 | Caller is not a system application. |
4228| 6800104 | Operation not allowed. |
4229
4230**示例:**
4231
4232```ts
4233let mode = asrProcessingController.getAsrNoiseSuppressionMode();
4234```
4235
4236### isWhispering<sup>12+</sup>
4237
4238isWhispering(): boolean;
4239
4240查询耳语状态。
4241
4242**系统接口:** 该接口为系统接口
4243
4244**系统能力:** SystemCapability.Multimedia.Audio.Capturer
4245
4246**返回值:**
4247
4248| 类型 | 说明                       |
4249|-------|--------------------------|
4250| boolean | 返回耳语状态,true为开启,false为关闭。 |
4251
4252**错误码:**
4253
4254以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4255
4256| 错误码ID   | 错误信息                                     |
4257|---------|------------------------------------------|
4258| 202 | Caller is not a system application. |
4259| 6800104 | Operation not allowed. |
4260
4261**示例:**
4262
4263```ts
4264let flag = asrProcessingController.isWhispering();
4265```
4266
4267### setAsrWhisperDetectionMode<sup>12+</sup>
4268
4269setAsrWhisperDetectionMode(mode: AsrWhisperDetectionMode): boolean
4270
4271设置耳语检测模式。
4272
4273**系统接口:** 该接口为系统接口
4274
4275**系统能力:** SystemCapability.Multimedia.Audio.Capturer
4276
4277**参数:**
4278
4279| 参数名  | 类型                  | 必填 | 说明     |
4280|------|---------------------|-------|--------|
4281| mode | [AsrWhisperDetectionMode](#asrwhisperdetectionmode12) | 是 | 耳语检测模式。 |
4282
4283**返回值:**
4284
4285| 类型 | 说明                                     |
4286|-------|----------------------------------------|
4287| boolean | 返回设置耳语检测模式结果,true为设置成功,false为设置失败。 |
4288
4289**错误码:**
4290
4291以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4292
4293| 错误码ID   | 错误信息                                     |
4294|---------|------------------------------------------|
4295| 202     | Caller is not a system application. |
4296| 401     | Parameter error. Possible causes: 1.Mandatory parameters unspecified; 2.Incorrect parameter types.                 |
4297| 6800101 | Parameter verification failed. |
4298| 6800104 | Operation not allowed.                 |
4299
4300**示例:**
4301
4302```ts
4303let flag = asrProcessingController.setAsrWhisperDetectionMode(audio.AsrWhisperDetectionMode.BYPASS);
4304```
4305
4306
4307### getAsrWhisperDetectionMode<sup>12+</sup>
4308
4309getAsrWhisperDetectionMode(): AsrWhisperDetectionMode
4310
4311获取耳语检测模式,同步返回结果。
4312
4313**系统接口:** 该接口为系统接口
4314
4315**系统能力:** SystemCapability.Multimedia.Audio.Capturer
4316
4317**返回值:**
4318
4319| 类型 | 说明     |
4320|-------|--------|
4321| [AsrWhisperDetectionMode](#asrwhisperdetectionmode12) | 耳语检测模式 |
4322
4323**错误码:**
4324
4325以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4326
4327| 错误码ID   | 错误信息                                     |
4328|---------|------------------------------------------|
4329| 202     | Caller is not a system application. |
4330| 6800104 | Operation not allowed.                 |
4331
4332**示例:**
4333
4334```ts
4335let mode = asrProcessingController.getAsrWhisperDetectionMode();
4336```
4337
4338
4339### setAsrVoiceControlMode<sup>12+</sup>
4340
4341setAsrVoiceControlMode(mode: AsrVoiceControlMode, enable: boolean): boolean
4342
4343设置在系统通话中上报mode及通话录音的上行通路的ASR音频通路选择。
4344
4345**系统接口:** 该接口为系统接口
4346
4347**系统能力:** SystemCapability.Multimedia.Audio.Capturer
4348
4349**参数:**
4350
4351| 参数名  | 类型                  | 必填 | 说明     |
4352|------|---------------------|-------|--------|
4353| mode | [AsrVoiceControlMode](#asrvoicecontrolmode12) | 是 | 音频通路模式。 |
4354| enable   | boolean             | 是 | 表示系统通话中上报mode及通话录音的上行通路的ASR音频通路选择开关状态。true表示打开,false表示关闭。 |
4355
4356**返回值:**
4357
4358| 类型 | 说明                                                             |
4359|-------|----------------------------------------------------------------|
4360| boolean | 返回设置在系统通话中上报mode及通话录音的上行通路的ASR音频通路选择的结果。true为设置成功,false为设置失败。 |
4361
4362**错误码:**
4363
4364以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4365
4366| 错误码ID   | 错误信息                                     |
4367|---------|------------------------------------------|
4368| 202     | Caller is not a system application. |
4369| 401     | Parameter error. Possible causes: 1.Mandatory parameters unspecified; 2.Incorrect parameter types.                 |
4370| 6800101 | Parameter verification failed. |
4371| 6800104 | Operation not allowed.                 |
4372
4373**示例:**
4374
4375```ts
4376let flag = asrProcessingController.setAsrVoiceControlMode(audio.AsrVoiceControlMode.AUDIO_2_VOICE_TX, true);
4377```
4378
4379### setAsrVoiceMuteMode<sup>12+</sup>
4380
4381setAsrVoiceMuteMode(mode: AsrVoiceMuteMode, enable: boolean): boolean
4382
4383在系统通话中,对ASR音频通路进行静音控制。
4384
4385**系统接口:** 该接口为系统接口
4386
4387**系统能力:** SystemCapability.Multimedia.Audio.Capturer
4388
4389**参数:**
4390
4391| 参数名  | 类型                                    | 必填 | 说明       |
4392|------|---------------------------------------|-------|----------|
4393| mode | [AsrVoiceMuteMode](#asrvoicemutemode12) | 是 | 静音控制模式。 |
4394| enable   | boolean                               | 是 | 表示在系统通话中设置ASR音频通路静音状态。true表示静音,false表示非静音。 |
4395
4396**返回值:**
4397
4398| 类型 | 说明                                               |
4399|-------|--------------------------------------------------|
4400| boolean | 返回在系统通话中,对ASR音频通路进行静音控制的结果。true为设置成功,false为设置失败。 |
4401
4402**错误码:**
4403
4404以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。
4405
4406| 错误码ID   | 错误信息                                     |
4407|---------|------------------------------------------|
4408| 202     | Caller is not a system application. |
4409| 401     | Parameter error. Possible causes: 1.Mandatory parameters unspecified; 2.Incorrect parameter types.                 |
4410| 6800101 | Parameter verification failed. |
4411| 6800104 | Operation not allowed.                 |
4412
4413**示例:**
4414
4415```ts
4416let flag = asrProcessingController.setAsrVoiceMuteMode(audio.AsrVoiceMuteMode.OUTPUT_MUTE, true);
4417```