Skip to content
pubscout

opus_dart

3.0.1, released 3 years ago by epnw.eu

Wraps libopus for Dart, providing encoding/decoding APIs and optional stream transformers.

WASM-ready
$ flutter pub add opus_dart
Source repository

What it does

It exposes libopus functionality via FFI, offering both low‑level bindings and a higher‑level Dart API for encoding PCM to Opus packets and decoding them back. The API includes simple and buffered encoders/decoders and stream transformers.

AI-written summary of version 3.0.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need Opus audio encoding/decoding in a Flutter or Dart app
  • You want a Dart‑friendly API that handles memory management
  • You need Web support via web_ffi

Skip it when

  • You only need a pure Dart implementation without native code
  • You are targeting platforms without libopus binaries

Strengths

  • Provides both low‑level bindings and high‑level API
  • Supports web via web_ffi
  • Includes stream transformers for easy PCM stream handling
  • Clear separation of simple vs buffered encoders for performance tuning

Weaknesses

  • Requires manual loading of libopus binaries
  • Memory must be manually freed to avoid leaks
  • No native build system, so distribution of binaries is manual

Setup

Kind
FFI (native library)
Effort
Medium
Code generation
No
Direct dependencies
2

Download and ship libopus binaries for each target platform, load them with DynamicLibrary (or web_ffi on web), call initOpus(lib) before using the API. No build_runner needed.

import 'package:opus_dart/opus_dart.dart';

void main(){
  // Load libopus (platform specific)
  final lib = /* DynamicLibrary.open(...) */;
  initOpus(lib);
  final encoder = SimpleOpusEncoder(sampleRate: 48000, channels: 2);
  final pcm = Uint8List.fromList([/* PCM data */]);
  final packet = encoder.encode(pcm);
  encoder.destroy();
}

Works with

Packages commonly used together with opus_dart: ones it builds on, ones built on it, and its own family.