• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Spatial Audio Management
2
3Spatial audio is an advanced audio technology that transforms traditional stereo sound into a three-dimensional experience. It enhances monaural, stereo, and surround sound by adding a sense of height, delivering an all-encompassing audio experience. Spatial audio immerses users in an interactive, spatially aware soundscape, making them feel as though they are truly present in the audio environment.
4
5Audio Vivid is an AI-driven audio codec standard. It is jointly formulated and released by the UHD World Association (UWA) and the Audio and Video Coding Standard Working Group (AVS). This audio format contains audio Pulse-Code Modulation (PCM) data and metadata, offering a more immersive listening experience over traditional stereo sources. Audio Vivid contains metadata information of audio content sources, which can reproduce the true auditory sensations of the physical and perceptual world.
6
7Spatial audio supports playback of multi-channel, stereo, and Audio Vivid formats, and can render binaural spatial audio through headphones. When paired with Audio Vivid format sources, spatial audio rendering can treat vocals and various instruments in music as independent sound objects. It redefines the position, movement trajectory, and volume of these sound objects, creating a fully immersive experience where sound surrounds and envelops the listener from all directions, including above. This provides a more immersive spatial audio experience, akin to being in a cinema or concert hall. When a device supports spatial audio and the spatial audio feature is enabled, playing Audio Vivid format sources can enhance the audio experience. For details about how to play Audio Vivid sources, see [Playing Audio Files in Audio Vivid Format](using-ohaudio-for-playback.md#playing-audio-files-in-audio-vivid-format).
8
9## How to Use
10
11For audio playback applications, you can check whether the device supports spatial audio and has enabled spatial audio.
12
13### Creating a Spatial Audio Instance
14
15Before using any APIs of AudioSpatializationManager, you must call [getSpatializationManager](../../reference/apis-audio-kit/arkts-apis-audio-AudioManager.md#getspatializationmanager18) to obtain an AudioSpatializationManager instance.
16
17  ```ts
18  import { audio } from '@kit.AudioKit';
19
20  let audioManager = audio.getAudioManager();
21  let audioSpatializationManager = audioManager.getSpatializationManager();
22  ```
23
24### Checking Whether a Device Supports Spatial Audio Rendering
25
26Use the **spatializationSupported** property in [AudioDeviceDescriptor](../../reference/apis-audio-kit/arkts-apis-audio-i.md#audiodevicedescriptor) to check whether a specified device supports spatial audio rendering. You need to use other audio APIs to obtain AudioDeviceDescriptor of a connected device or the current audio device.
27
28  ```ts
29  import { audio } from '@kit.AudioKit';
30  import { BusinessError } from '@kit.BasicServicesKit';
31
32  const deviceDescriptors: audio.AudioDeviceDescriptors = audioRoutingManager.getDevicesSync(audio.DeviceFlag.OUTPUT_DEVICES_FLAG);
33  for (let i = 0; i < deviceDescriptors.length; i++) {
34    console.info('deviceDescriptor deviceRole: ${deviceDescriptors[i].deviceRole}');
35    console.info('deviceDescriptor deviceType: ${deviceDescriptors[i].deviceType}');
36    console.info('deviceDescriptor name: ${deviceDescriptors[i].name}');
37    console.info('deviceDescriptor spatializationSupported: ${deviceDescriptors[i].spatializationSupported}');
38  }
39  ```
40
41### Checking the Status of Spatial Audio Rendering of the Current Device
42
43Call [isSpatializationEnabledForCurrentDevice](../../reference/apis-audio-kit/arkts-apis-audio-AudioSpatializationManager.md#isspatializationenabledforcurrentdevice18) to check whether spatial audio rendering is enabled for the current device.
44
45- If **true** is returned, spatial audio rendering is enabled for the current device. If **false** is returned, it is disabled.
46- Spatial audio rendering takes effect only when the current device support spatial audio rendering.
47
48  ```ts
49  import { audio } from '@kit.AudioKit';
50
51  let isSpatializationEnabledForCurrentDevice: boolean = audioSpatializationManager.isSpatializationEnabledForCurrentDevice();
52  console.info(`AudioSpatializationManager isSpatializationEnabledForCurrentDevice: ${isSpatializationEnabledForCurrentDevice}`);
53  ```
54
55**Listening for Spatial Audio Rendering Status Changes of the Current Device**
56
57Call [on('spatializationEnabledChangeForCurrentDevice')](../../reference/apis-audio-kit/arkts-apis-audio-AudioSpatializationManager.md#onspatializationenabledchangeforcurrentdevice18) to subscribe to the spatial audio rendering status change event of the current device.
58
59If **true** is returned, spatial audio rendering is enabled. If **false** is returned, it is disabled.
60
61```ts
62import { audio } from '@kit.AudioKit';
63
64audioSpatializationManager.on('spatializationEnabledChangeForCurrentDevice', (isSpatializationEnabledForCurrentDevice: boolean) => {
65  console.info(`isSpatializationEnabledForCurrentDevice: ${isSpatializationEnabledForCurrentDevice}`);
66});
67```
68
69**Canceling Listening for Spatial Audio Rendering Status Changes of the Current Device**
70
71Call [off('spatializationEnabledChangeForCurrentDevice')](../../reference/apis-audio-kit/arkts-apis-audio-AudioSpatializationManager.md#offspatializationenabledchangeforcurrentdevice18) to unsubscribe from the spatial audio rendering status change event of the current device.
72
73```ts
74import { audio } from '@kit.AudioKit';
75audioSpatializationManager.off('spatializationEnabledChangeForCurrentDevice');
76```
77