本示例主要展示音频低时延录制和播放的相关功能。
| Files | Last commit | Last update |
|---|---|---|
| 8 months ago | ||
| 5 months ago | ||
| 3 months ago | ||
| 7 months ago | ||
| 9 months ago | ||
| 8 months ago | ||
| 3 months ago | ||
| 3 months ago | ||
| 3 months ago | ||
| 2 years ago | ||
| 3 months ago |
Recording Audio Using AudioCapturer (C++)
Overview
This sample demonstrates how to implement low-latency audio recording using AudioCapturer on the C/C++ side based on the OH_Audio capabilities. By referring to this sample, you can learn how to use OH_Audio to develop audio recording scenarios.
Preview
| Home Page | Recording Page |
|---|---|
![]() |
![]() |
How to Use
- When you open the sample, a dialog box is displayed, asking you to grant the microphone permission. Tap Allow. If you tap Deny, recording cannot be performed. If you want to use recording at a later time, you must grant the permission to the application on the system Settings page.
- Tap the recording button to start recording. The recording timer starts.
- Tap the pause button to pause the recording. The recording timer stops.
- Tap the continue button to continue recording. The recording timer continues.
- After the recording is stopped, the recording result is generated. Tap the play button to play the recording.
Project Directory
├──entry/src/main/cpp/
│ ├──types
│ │ └──libentry
│ │ ├──index.d.ts // APIs exported
│ │ └──oh-package.json5 // Configuration management file
│ ├──AudioRecording.cpp // Native APIs called
│ └──CMakeLists.txt // CMake build script
├──entry/src/main/ets // UI layer
│ ├──common // Common modules
│ │ └──Constants.ets // Constants
│ ├──components
│ │ └──RecordDialog.ets // Recording dialog page
│ ├──entryability // App entry function
│ │ └──EntryAbility.ets
│ ├──model
│ │ └──RecordFileInfo.ets // Recorded file data
│ ├──pages
│ │ └──Index.ets // Home page
│ └──utils // Component modules
│ ├──BackgroundTaskUtil.ets // Background task utility
│ ├──Logger.ets // Log utility
│ ├──PermissionUtil.ets // Permission utility
│ └──StringUtil.ets // String utility
└──entry/src/main/resources // Static resources
How to Implement
- Create an AudioCapturer object on the native side when the recording page is displayed.
- Configure AudioCapturer, including the audio data and callback function.
- Enable AudioCapturer to start audio recording.
- Tap the button to complete the recording.
Required Permissions
Audio recording involves the following permission:
- ohos.permission.MICROPHONE: allows an application to use the microphone.
- ohos.permission.KEEP_BACKGROUND_RUNNING: allows an application to apply for a continuous task of the special type.
Dependencies
None
Constraints
- This sample is only supported on bar-type phones running standard systems.
- The HarmonyOS version must be HarmonyOS 6.0.2 Release or later.
- The DevEco Studio version must be DevEco Studio 6.0.2 Release or later.
- The HarmonyOS SDK version must be HarmonyOS 6.0.2 Release SDK or later.

