1# Selecting the Appropriate Audio Stream Types 2 3[Audio stream](audio-kit-intro.md#introduction-to-audio-streams) types are crucial for determining the mode of audio playback and recording. For audio playback streams, the stream type is determined by [StreamUsage](../../reference/apis-audio-kit/arkts-apis-audio-e.md#streamusage). For audio recording streams, the stream type is determined by [SourceType](../../reference/apis-audio-kit/arkts-apis-audio-e.md#sourcetype8). These types pose a significant impact on volume control, audio focus management, and input/output device selection. 4 5To ensure that the audio behavior meets expectations and delivers a superior user experience, you need to select an appropriate audio stream type based on the use cases and requirements. 6 7This topic describes [typical audio stream types and their use cases](#typical-audio-stream-types-and-use-cases) and [their effects on audio services](#effects-of-audio-stream-types-on-audio-services). It also describes how to [set the audio stream type](#setting-the-audio-stream-type) when you use different methods to implement audio playback and recording. 8 9## Typical Audio Stream Types and Use Cases 10 11### Stream Types for Audio Playback 12 13The following table describes the typical stream types used for audio playback. The type is specified by [StreamUsage](../../reference/apis-audio-kit/arkts-apis-audio-e.md#streamusage). 14 15| Stream Type| Use Case| 16| ---------- | ---------- | 17| STREAM_USAGE_MUSIC | Music playback and other media scenarios, for example, using [SoundPool](../media/using-soundpool-for-playback.md) to play short sounds.| 18| STREAM_USAGE_MOVIE | Playing various video content such as short videos, movies, and TV series.| 19| STREAM_USAGE_AUDIOBOOK | Playing audiobooks, news, and podcasts.| 20| STREAM_USAGE_GAME | In-game background scores and character dubbing, ensuring uninterrupted background music. It is recommended that you use **STREAM_USAGE_VOICE_COMMUNICATION** for in-game voice.| 21| STREAM_USAGE_NAVIGATION | Voice broadcast in navigation scenarios.| 22| STREAM_USAGE_VOICE_MESSAGE | Playing voice short messages.| 23| STREAM_USAGE_VOICE_COMMUNICATION | VoIP voice calls.| 24| STREAM_USAGE_ALARM | Playing alarms.| 25| STREAM_USAGE_RINGTONE | Playing ringtones for VoIP calls.| 26| STREAM_USAGE_NOTIFICATION | Playing notification tones and prompt tones.| 27 28### Stream Types for Audio Recording 29 30The following table describes the typical stream types used for audio recording. The type is specified by [SourceType](../../reference/apis-audio-kit/arkts-apis-audio-e.md#sourcetype8). 31 32| Stream Type| Use Case| 33| ---------- | ---------- | 34| SOURCE_TYPE_MIC | Common audio recording.| 35| SOURCE_TYPE_RECOGNITION<sup>9+</sup> | Voice recognition.| 36| SOURCE_TYPE_PLAYBACK_CAPTURE | (Deprecated in API version 12) Recording raw audio data sent by other applications to the system for playback.<br>Audio Kit does not provide APIs for internal recording. You can use [AVScreenCapture](../../reference/apis-media-kit/capi-avscreencapture.md) to perform internal recording.| 37| SOURCE_TYPE_VOICE_COMMUNICATION | VoIP voice calls.| 38| SOURCE_TYPE_VOICE_MESSAGE | Recording voice short messages.| 39| SOURCE_TYPE_CAMCORDER<sup>13+</sup> | Camera recording.| 40| SOURCE_TYPE_UNPROCESSD<sup>14+</sup> | Obtaining pure audio data captured by the microphone (without any system processing).| 41| SOURCE_TYPE_LIVE<sup>20+</sup> | Live streaming. This source type provides system echo cancellation capabilities on supported platforms.| 42 43## Effects of Audio Stream Types on Audio Services 44 45Different stream types affect user experience in volume control and system performance in adjusting the audio focus and selecting input/output devices. In addition, the system configures corresponding optimization processing strategies for the captured audio data based on the recording stream type. Therefore, the recording stream type affects the audio recording quality. For example, using **SOURCE_TYPE_MIC** instead of **SOURCE_TYPE_VOICE_COMMUNICATION** in a VoIP call scenario may disable noise reduction and ambient sound elimination optimizations, leading to a poor VoIP call experience. You are advised to select the appropriate audio stream type based on the service scenario. 46 47### Volume Control 48 49The audio playback stream type (specified by [StreamUsage](../../reference/apis-audio-kit/arkts-apis-audio-e.md#streamusage)) determines the volume type (specified by [AudioVolumeType](../../reference/apis-audio-kit/arkts-apis-audio-e.md#audiovolumetype)) to which the audio stream belongs. Each volume type (such as **MEDIA**, **RINGTONE**, **ALARM**, and **VOICE_CALL**) has an independent volume value, which can be adjusted independently on the UI. 50 51The table below lists the mappings between the typical audio playback stream types and volume types. 52 53| Stream Type| Volume Type| 54| ---------- | ---------- | 55| MUSIC, MOVIE, AUDIOBOOK, GAME| MEDIA| 56| RINGTONE, NOTIFICATION| RINGTONE| 57| VOICE_COMMUNICATION | VOICE_CALL| 58| ALARM | ALARM| 59 60### Adjusting the Audio Focus 61 62The audio stream type plays a key role in audio focus management. Different types of audio streams have different default priorities and processing modes for the audio focus. 63 64When an application starts audio playback or recording, the system automatically applies for focus based on the audio stream type. This may interrupt or duck other audio streams. For details about the audio focus, see [Introduction to Audio Focus and Audio Session](audio-playback-concurrency.md). 65 66This section describes only how the typical audio stream types affect the audio focus. 67 68- When a Navigation stream starts playing, the Music stream that is playing will be ducked. After the Navigation stream ends, the volume of the Music stream will be restored. 69 70- When a Movie stream starts playing, the Music stream that is playing will be stopped. When the Movie stream ends, the Music stream will not be automatically resumed, and the corresponding application will not receive any resume notification. 71 72- When a VoiceCommunication stream starts, the Music stream that is playing will be paused. When the VoiceCommunication stream ends, the music application will receive a notification to resume the playback. 73 74- The Music stream and Game stream can be mixed and played concurrently without affecting each other. 75 76- When a VoiceMessage stream starts, the Music stream that is playing will be paused. When the VoiceMessage stream ends, the music application will receive a notification to resume the playback. 77 78### Selecting Input/Output Devices 79 80The system selects an input/output device based on the audio stream type. 81 82The following lists the input/output devices selected for the typical audio stream types. 83 84- For a MUSIC stream, the default output device is a speaker. 85 86- For a VoiceCommunication stream, the default input device is a microphone, and the default output device is an earpiece. 87 88- For an Alarm stream, the default output device is a speaker. If a Bluetooth headset is connected before an ALARM stream is played, the audio is output from both the speaker and Bluetooth headset. 89 90If the default input/output devices do not meet service requirements, you can call related APIs to change the devices. When [using AudioRenderer to develop audio playback](using-audiorenderer-for-playback.md), you can call [setDefaultOutputDevice](../../reference/apis-audio-kit/arkts-apis-audio-AudioRenderer.md#setdefaultoutputdevice12) to set the default sound device. 91 92## Setting the Audio Stream Type 93 94The application can implement audio playback or recording by using a plurality of methods. Therefore, manners of setting the audio stream type are also different. 95 96Common methods for setting the audio playback stream type are as follows: 97 98- **[Using AudioRenderer for Audio Playback](using-audiorenderer-for-playback.md)** 99 100 Pass [StreamUsage](../../reference/apis-audio-kit/arkts-apis-audio-e.md#streamusage) in [createAudioRenderer](../../reference/apis-audio-kit/arkts-apis-audio-f.md#audiocreateaudiorenderer8) to specify the stream type. 101 102 The **options** parameter in **createAudioRenderer** is of the **AudioRendererOptions** type and contains the **AudioRendererInfo** struct, in which **AudioRendererInfo.usage** specifies the stream type. 103 104- **[Using OHAudio for Audio Playback](using-ohaudio-for-playback.md)** 105 106 Pass [OH_AudioStream_Usage](../../reference/apis-audio-kit/capi-native-audiostream-base-h.md#oh_audiostream_usage) in [OH_AudioStreamBuilder_SetRendererInfo](../../reference/apis-audio-kit/capi-native-audiostreambuilder-h.md#oh_audiostreambuilder_setrendererinfo) to specify the stream type. 107 108- **[Using AVPlayer for Audio Playback (ArkTS)](../media/using-avplayer-for-playback.md)** 109 110 Set the **audioRendererInfo** [property](../../reference/apis-media-kit/arkts-apis-media-AVPlayer.md#properties) of the AVPlayer. **AVPlayer.audioRendererInfo** is of the **audio.AudioRendererInfo** type. You can use **AudioRendererInfo.usage** to specify [StreamUsage](../../reference/apis-audio-kit/arkts-apis-audio-e.md#streamusage). 111 112 > **NOTE** 113 > The **audioRendererInfo** property of the AVPlayer can be set only in the initialized state. 114 > 115 > If the application does not set this property, the AVPlayer performs default processing. If the media source contains videos, the default value of **usage** is **STREAM_USAGE_MOVIE**. Otherwise, the default value of **usage** is **STREAM_USAGE_MUSIC**. 116 117- **[Using AVPlayer for Audio Playback (C/C++)](../media/using-ndk-avplayer-for-playback.md)** 118 119 Pass [OH_AudioStream_Usage](../../reference/apis-audio-kit/capi-native-audiostream-base-h.md#oh_audiostream_usage) in [OH_AVPlayer_SetAudioRendererInfo](../../reference/apis-media-kit/capi-avplayer-h.md#oh_avplayer_setaudiorendererinfo) to specify the stream type. 120 121- **[Using SoundPool for Audio Playback](../media/using-soundpool-for-playback.md)** 122 123 Pass [StreamUsage](../../reference/apis-audio-kit/arkts-apis-audio-e.md#streamusage) in [createSoundPool](../../reference/apis-media-kit/arkts-apis-media-f.md#mediacreatesoundpool10) to specify the stream type. 124 125Common methods for setting the audio recording stream type are as follows: 126 127- **[Using AudioCapturer for Audio Recording](using-audiocapturer-for-recording.md)** 128 129 Pass [SourceType](../../reference/apis-audio-kit/arkts-apis-audio-e.md#sourcetype8) in [createAudioCapturer](../../reference/apis-audio-kit/arkts-apis-audio-f.md#audiocreateaudiocapturer8) to specify the stream type. 130 131 The **options** parameter in **createAudioCapturer** is of the **AudioCapturerOptions** type and contains **AudioCapturerInfo**, in which **AudioCapturerInfo.source** specifies the source type. 132 133- **[Using OHAudio for Audio Recording](using-ohaudio-for-recording.md)** 134 135 Pass [OH_AudioStream_SourceType](../../reference/apis-audio-kit/capi-native-audiostream-base-h.md#oh_audiostream_sourcetype) in [OH_AudioStreamBuilder_SetCapturerInfo](../../reference/apis-audio-kit/capi-native-audiostreambuilder-h.md#oh_audiostreambuilder_setcapturerinfo) to specify the stream type. 136 137- **[Using AVRecorder for Audio Recording](../media/using-avrecorder-for-recording.md)** 138 139 Pass [AudioSourceType](../../reference/apis-media-kit/arkts-apis-media-e.md#audiosourcetype9) in [AVRecorder.prepare](../../reference/apis-media-kit/arkts-apis-media-AVRecorder.md#prepare9-1) to specify the stream type. 140 141 The **config** parameter in **AVRecorder.prepare** is of the **AVRecorderConfig** type, in which **AVRecorderConfig.audioSourceType** specifies the audio source type. 142 143<!--no_check-->