AMR Plugin for Flutter

pub package license

A Flutter plugin that provides AMR (Adaptive Multi-Rate) audio format conversion capabilities for both iOS and Android platforms. This plugin supports both AMR-NB and AMR-WB formats and enables bidirectional conversion between AMR and WAV audio formats in your Flutter applications.

Features

  • AMR-NB Support: Encode and decode AMR-NB audio format
  • AMR-WB Support: Encode and decode AMR-WB audio format
  • WAV to AMR: Convert WAV audio files to AMR-NB format
  • AMR to WAV: Convert AMR-NB/AMR-WB audio files to WAV format
  • Cross-Platform: Supports both iOS and Android platforms
  • Advanced Audio Processing: High-quality resampling, noise reduction, and audio enhancement
  • Multiple WAV Formats: Supports PCM, μ-law (G.711), and various bit depths
  • Memory Optimized: Efficient processing for large audio files with chunked processing
  • High Performance: Built on top of OpenCore AMR libraries (iOS) and MediaCodec (Android)

Installation

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

dependencies:
  amr_plugin: ^0.0.1

Then run:

flutter pub get

iOS Setup

For iOS, you need to add the following to your ios/Podfile:

platform :ios, '12.0'

The plugin will automatically handle the OpenCore AMR framework integration.

Android Setup

For Android, the plugin uses the built-in MediaCodec API. No additional setup is required. The plugin will automatically detect available AMR encoders/decoders on the device.

Minimum Android API Level: 21 (Android 5.0)

Platform Support

This plugin supports both iOS and Android platforms:

  • iOS: Uses OpenCore AMR libraries for high-quality AMR encoding/decoding
  • Android: Uses MediaCodec API with advanced audio processing pipeline

Usage

Basic Example

import 'package:amr_plugin/amr_plugin.dart';

// Initialize the plugin
final amrPlugin = AmrPlugin();

// Convert WAV file to AMR format
try {
  final resultPath = await amrPlugin.convertWavToAmr(
    '/path/to/input.wav',
    sampleRate: 8000,
    bitRate: 12200,
  );
  if (resultPath != null) {
    print('Conversion successful: $resultPath');
  } else {
    print('Conversion failed');
  }
} catch (e) {
  print('Conversion failed: $e');
}

// Convert AMR file to WAV format
try {
  final resultPath = await amrPlugin.convertAmrToWav(
    '/path/to/input.amr',
    sampleRate: 8000,
  );
  if (resultPath != null) {
    print('Conversion successful: $resultPath');
  } else {
    print('Conversion failed');
  }
} catch (e) {
  print('Conversion failed: $e');
}

Advanced Usage

// Example: Play converted audio file
// You can use audio_player package to play the converted files
// import 'package:audioplayers/audioplayers.dart';
// 
// final audioPlayer = AudioPlayer();
// await audioPlayer.play(DeviceFileSource(resultPath));

API Reference

AmrPlugin

The main class for AMR audio operations.

Methods

  • convertWavToAmr(String inputPath, {int sampleRate = 8000, int bitRate = 12200}): Convert WAV file to AMR format
  • convertAmrToWav(String inputPath, {int sampleRate = 8000}): Convert AMR file to WAV format

Supported Conversions

This plugin supports the following format conversions:

  • WAV → AMR: Convert WAV audio files to AMR format
  • AMR → WAV: Convert AMR audio files to WAV format

Supported Formats

Input Formats

  • WAV (.wav): PCM, μ-law (G.711), various bit depths (8, 16, 24, 32-bit)
  • AMR (.amr): AMR-NB and AMR-WB formats

Output Formats

  • AMR (.amr): AMR-NB formats
  • WAV (.wav): 16-bit PCM format

Requirements

  • iOS: 12.0+
  • Android: API Level 21+ (Android 5.0+)
  • Flutter: 3.0.0+

Dependencies

This plugin uses the following native libraries:

iOS

  • OpenCore AMR: High-quality AMR encoding/decoding libraries

Android

  • MediaCodec API: Android's built-in media codec framework
  • Custom Audio Processing: Advanced audio processing pipeline for noise reduction and quality enhancement

Contributing

We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Setup

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

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

Acknowledgments

Support

If you encounter any issues or have questions, please:

  1. Check the Issues page
  2. Create a new issue if your problem isn't already reported
  3. Join our Discussions for general questions

Changelog

See CHANGELOG.md for a list of changes and version history.