audio_codec 0.0.2

SDKdartflutter
Platformandroidioswindowslinuxmacos

A library to decode and perhaps encode audios

audio_codecs

pub.dev badge

A Dart library for decoding (and potentially encoding) audio files. This package provides a convenient way to work with various audio codecs within your Dart and Flutter applications.

Codecs Support

CodecDecoding StatusEncoding StatusNotes
FLACGood-Decoding is functional, may have some minor audio glitches.
MP3--Not yet implemented.
OPUS--Not yet implemented.
WAV-GoodWriting is supported.
PCMExcellentExcellent

Status Levels

The "Status" column in the Codecs table uses the following quality indicators:

StatusDescription
-Not started yet.
PassableThe codec is partially implemented. For decoding, this might mean the file can be decoded, but with issues.
GoodThe codec is mostly functional. For decoding, it might mean files can be decoded but with some audible glitches.
ExcellentThe codec is fully implemented and considered stable. For decoding, it means no audible glitches.

Installation

Add audio_codecs to your pubspec.yaml:

dependencies:
  audio_codecs: ^0.0.1

Then, run:

dart pub get

Usage

import 'dart:io';
import 'dart:typed_data';

import 'package:audio_codec/src/flac/flac_decoder.dart';
import 'package:audio_codec/src/wav/wav_encoder.dart';

void main() {
  final flacFile = File('test.flac');

  final decoder = FlacDecoder(track: flacFile);
  final result = decoder.decode();

  final pcmSamples = Int32List(
    result.streamInfoBlock!.totalSamples * result.streamInfoBlock!.channels,
  );

  int frameNumber = 0;

  while (decoder.hasNextFrame()) {
    final frame = decoder.readFrame();

    writeFrameToPcm(
      pcmSamples,
      frame,
      frameNumber,
      result.streamInfoBlock!.sampleRate,
    );

    frameNumber++;
  }

  decoder.close();

  WavEncoder(
    sampleRate: result.streamInfoBlock!.sampleRate,
    numChannels: result.streamInfoBlock!.channels,
    bitDepth: result.streamInfoBlock!.bitsPerSample,
  ).encode(
    File("output.wav"),
    pcmSamples,
  );
}