目录

About This Kit

Audio Kit provides scenario-specific audio playback and recording APIs to help you quickly build HD audio collection and immersive playback capabilities.

Highlights

Audio Architecture

You can use the APIs provided by Audio Kit to access the playback, recording, and audio strategy management capabilities of the audio system, thereby interacting with the corresponding audio hardware. The audio architecture defines how the system encapsulates and manages audio hardware capabilities, as illustrated in the figure below:

Application

You can use the public APIs provided by Audio Kit and the software and hardware capabilities provided by the audio system to implement playback and recording required by applications.

NAPI

NAPI, an interface introduced by Node.js for developing C++ modules, encapsulates the underlying operating system capabilities and provides ArkTS interfaces. NAPI enables mutual access between ArkTS and C/C++ code.

Native framework

At the native framework layer, the audio system implements interfaces for playing, recording, volume control, device routing, and audio effect processing, and connects to the audio service through inter-process interfaces.

Native SystemAbility

The audio_server process hosts the software-implemented audio system functional components, providing rich audio strategy management and data processing capabilities. The components connect to the HAL layer through HDIs to utilize audio hardware capabilities.

HAL

The HAL provides services through a set of HDIs. Different audio hardware developers implement the HDIs, enabling the audio service to play and record through various types of audio devices.

Kernel

The kernel driver interacts with the audio hardware. Multiple kernels, such as Linux, LiteOS, and HarmonyOS, can be selected for different operating systems.

Development Description

For every functionality provided by the multimedia subsystem, you will learn multiple implementation modes, each of which corresponds to a specific usage scenario. You will also learn the sub-functionalities in these scenarios. For example, in the Audio Playback chapter, you will learn audio concurrency strategies, volume management, and output device processing methods. All these will help you develop an application with more comprehensive features.

This development guide applies only to audio playback or recording, which are implemented by Audio Kit. The UI, image processing, media storage, or other related capabilities are not covered.

Before developing an audio feature, especially before implementing audio data processing, you are advised to understand the following acoustic concepts. This will help you understand how the APIs control the audio module and how to develop audio and video applications that are easier to use and deliver better experience.

Introduction to Audio Streams

Before developing audio applications, you need to understand what an audio stream is. It is a key concept in the HarmonyOS audio system and will be mentioned multiple times in subsequent chapters.

The audio stream can be used in playback and recording scenarios, and supports independent volume adjustment and audio device routing.

The basic audio stream information is defined by AudioStreamInfo, which includes the sampling, audio channel, bit width, and encoding information. It describes the basic attributes of audio data and is mandatory for creating an audio playback or recording stream. To enable the audio module to correctly process audio data, the configured basic information must match the transmitted audio data.

[h2]Audio Stream Usage Scenario Information

In addition to the basic information (which describes only audio data), an audio stream has usage scenario information. This is because audio streams differ in the volume, device routing, and concurrency strategy. The system chooses an appropriate processing strategy for an audio stream based on the usage scenario information, thereby delivering better user experience.

Supported Audio Formats

The APIs of the audio module support PCM encoding, including AudioRenderer, AudioCapturer, TonePlayer, and OpenSL ES.

Be familiar with the following about the audio format:

Supported Emulators

This kit supports the Emulator, but there are some differences in feature support between real devices and the Emulator: