audio-native:基于OH_Audio的音频低时延录制项目

本示例主要展示音频低时延录制和播放的相关功能。

Branch2Tags0
FilesLast commitLast 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

  1. 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.
  2. Tap the recording button to start recording. The recording timer starts.
  3. Tap the pause button to pause the recording. The recording timer stops.
  4. Tap the continue button to continue recording. The recording timer continues.
  5. 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

  1. Create an AudioCapturer object on the native side when the recording page is displayed.
  2. Configure AudioCapturer, including the audio data and callback function.
  3. Enable AudioCapturer to start audio recording.
  4. Tap the button to complete the recording.

Required Permissions

Audio recording involves the following permission:

  1. ohos.permission.MICROPHONE: allows an application to use the microphone.
  2. ohos.permission.KEEP_BACKGROUND_RUNNING: allows an application to apply for a continuous task of the special type.

Dependencies

None

Constraints

  1. This sample is only supported on bar-type phones running standard systems.
  2. The HarmonyOS version must be HarmonyOS 6.0.2 Release or later.
  3. The DevEco Studio version must be DevEco Studio 6.0.2 Release or later.
  4. The HarmonyOS SDK version must be HarmonyOS 6.0.2 Release SDK or later.

Introduction

本示例主要展示音频低时延录制和播放的相关功能。

Customize your domain