本示例基于AudioCapturer(ArkTS)实现了音频PCM录制。AudioCapturer用于录制PCM(Pulse Code Modulation)音频数据,开发者可以基于本示例实现录制音频PCM,适用于实现更灵活的录制功能。
Access rate limit exceeded. Please log in to continue.
Recording Audio Using AudioCapturer (ArkTS)
Overview
This sample shows how to record Pulse Code Modulation (PCM) audio using AudioCapturer (ArkTS), which is suitable if you want to implement more flexible recording features.
Preview
| Bar phone | Bi-fold phone | Tablet |
|---|---|---|
![]() |
![]() |
![]() |
How to Use
- Open the app and tap the recording button to start recording audio.
- After the recording is complete, return to the home page and tap the audio file to play it.
Project Directory
├──ets // UI layer.
│ ├──common // Common modules.
│ │ └──Constants.ets // Constants.
│ ├──components
│ │ └──RecordDialog.ets // Recording dialog page.
│ ├──controller // Controller module.
│ │ ├──AudioCapturerController.ets // Audio capture class of AudioCapturer.
│ │ └──AudioRendererController.ets // Playback class of AudioRenderer.
│ ├──entryability // App entry function.
│ │ └──EntryAbility.ets
│ ├──entrybackupability
│ │ └──EntryBackupAbility.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.
├──resources // Static resources.
└──module.json5 // Module configuration.
How to Implement
- Create an AudioCapturer object 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
- ohos.permission.MICROPHONE: allows an app to use the microphone.
- ohos.permission.KEEP_BACKGROUND_RUNNING: allows an app to apply for a continuous task of the special type.
Constraints
- This sample is only supported on bar-type phones, bi-fold devices (Mate X series), tri-fold devices, widescreen foldable devices, tablets, PCs running standard systems.
- The HarmonyOS version must be HarmonyOS 6.0.2 Release or later.
- The DevEco Studio version must be DevEco Studio 6.1.0 Release or later.
- The HarmonyOS SDK version must be HarmonyOS 6.1.0 Release SDK or later.
Introduction
本示例基于AudioCapturer(ArkTS)实现了音频PCM录制。AudioCapturer用于录制PCM(Pulse Code Modulation)音频数据,开发者可以基于本示例实现录制音频PCM,适用于实现更灵活的录制功能。
Customize your domain

