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