搜索插件、代码仓与 APP 分类

插件详情v1.0.0

native_audio_trimmer

一个用于在 Android 和 iOS 上剪裁音频文件的 Flutter 插件,无需使用 FFmpeg。

AndroidiOS
近 30 天下载
225
喜欢数
6
Pub 分数
150

安装插件

flutter pub add native_audio_trimmer

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

NativeAudioTrimmer 是一个 Flutter 插件,可在 Android 和 iOS 设备上实现音频文件剪辑,无需依赖 FFmpeg。它利用原生平台功能,在应用内直接提供高效、轻量级的音频处理。该插件支持常见音频格式,并提供简单的 API 来设置开始和结束时间,以提取所需的音频片段。适用于需要基本音频编辑功能的应用程序,例如语音笔记剪辑或播客片段截取。

适合场景

  • 剪裁语音备忘录
  • 编辑短音频片段
  • 准备音频片段以供分享
  • 在录音应用中集成音频编辑功能
  • 创建自定义音频预览

主要特点

  • 无 FFmpeg 依赖
  • 跨平台支持(Android 和 iOS)
  • 简单API用于开始/结束时间选择
  • 轻量且快速的处理
  • 使用原生音频处理

适合对象

  • 开发音频录制应用的开发者
  • 需要基本音频编辑的应用
  • 项目避免使用重型依赖
  • 带有语音笔记功能的移动应用
  • 教育或内容创作工具

使用建议

  • 仅限基本修剪操作
  • 不支持高级音频效果
  • 需要平台特定权限
  • 可能因设备而存在格式限制
  • 性能取决于设备硬件

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

native_audio_trimmer

A Flutter plugin for trimming audio files on both Android and iOS platforms without using FFmpeg. This native audio editor provides powerful audio manipulation capabilities, perfect for Flutter audio trimming in apps, podcast trimming, and voice note editing.

Features

  • Trim audio files by specifying start and end times
  • Native implementation for iOS (using AVAssetExportSession)
  • Native implementation for Android (using MediaExtractor, MediaCodec, and MediaMuxer)
  • No FFmpeg dependency, resulting in smaller app size and faster builds
  • Support for multiple audio formats

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  native_audio_trimmer: ^1.0.0
Android

Add the storage permissions to your AndroidManifest.xml if you're targeting Android 12 or below and need to access files outside of your app's directory:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

For Android 13+ (API level 33+), you may need to request more specific permissions depending on your use case:

<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
iOS

No additional setup is required for iOS.

Usage

import 'package:native_audio_trimmer/native_audio_trimmer.dart';

// Create an instance of AudioTrimmer
final audioTrimmer = AudioTrimmer();

// Trim an audio file
try {
  String inputPath = '/path/to/input.mp3';
  String outputPath = '/path/to/output.m4a';
  
  // Trim from 10 seconds to 30 seconds
      // Trim audio
      final trimmedFilePath = await NativeAudioTrimmer.trimAudio(
        inputPath: inputPath,
        outputPath: outputPath,
        startTimeInSeconds: 10.0, // Start time in seconds,
        endTimeInSeconds: 30.0, // End time in seconds,
      );
  
  print('Trimmed audio saved at: $trimmedFilePath');
} catch (e) {
  print('Error trimming audio: $e');
}

Example

Check out the example app in the example folder to see a complete implementation of audio file selection, trimming, and playback.

To run the example app:

cd example
flutter run

Implementation Details

iOS

On iOS, this plugin uses the native AVAssetExportSession to perform audio trimming operations. The resulting audio file is saved in the .m4a format.

Android

On Android, the plugin uses a combination of MediaExtractor, MediaCodec, and MediaMuxer to extract, process, and save the audio data between the specified start and end times.

Supported Formats

Input Formats
  • MP3
  • M4A/AAC
  • WAV
  • OGG (Android only)
  • FLAC
Output Format
  • M4A (AAC) for both platforms

Limitations

  • The plugin currently only outputs to M4A format
  • Very large audio files may require additional memory
  • Some exotic audio formats might not be supported by the native APIs

Contributing

Contributions are welcome! If you find a bug or want a feature, please open an issue on GitHub.

License

This project is licensed under the MIT License - see the LICENSE file for details.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。