audio_codec 0.0.2 copy "audio_codec: ^0.0.2" to clipboard
audio_codec: ^0.0.2 copied to clipboard

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 #

Codec Decoding Status Encoding Status Notes
FLAC Good - Decoding is functional, may have some minor audio glitches.
MP3 - - Not yet implemented.
OPUS - - Not yet implemented.
WAV - Good Writing is supported.
PCM Excellent Excellent

Status Levels #

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

Status Description
- Not started yet.
Passable The codec is partially implemented. For decoding, this might mean the file can be decoded, but with issues.
Good The codec is mostly functional. For decoding, it might mean files can be decoded but with some audible glitches.
Excellent The 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
copied to clipboard

Then, run:

dart pub get
copied to clipboard

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,
  );
}
copied to clipboard
2
likes
150
points
40
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.21 - 2025.04.05

A library to decode and perhaps encode audios

Homepage
Repository (GitHub)
View/report issues

Topics

#audio #codec #decoder #encoder

Documentation

API reference

License

MIT (license)

Dependencies

convert, crypto

More

Packages that depend on audio_codec