搜尋套件、儲存庫與 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.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。