Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

framer

Re-chunks a stream of raw PCM audio bytes, of any origin, into fixed-size frames suitable for a codec such as Opus.

Features

  • Buffers irregular-sized PCM chunks and emits clean, fixed-size frames
  • Frame size can be given directly in bytes or derived from an AudioFormat and a target Duration
  • Trailing bytes on stream end can be zero-padded to a full frame or returned as-is
  • StreamTransformer wrapper for use directly in a Stream<Uint8List> pipeline

Getting started

import 'package:framer/framer.dart';

AudioFormat currently only supports SampleEncoding.pcm16le (16-bit signed little-endian, interleaved).

Usage

const format = AudioFormat(sampleRate: 48000, channels: 2); // PCM16LE

final framer = PcmFramer.forDuration(
  format: format,
  frameDuration: const Duration(milliseconds: 20),
);

await for (final chunk in pcmByteStream) {
  for (final frame in framer.addChunk(chunk)) {
    // send `frame` to an encoder — always exactly the configured size
  }
}

final tail = framer.flush(); // trailing partial frame, zero-padded by default

Or as a stream transform:

pcmByteStream.transform(framer.asTransformer()).listen(encoder.encode);

Every frame addChunk emits lands on a whole multiple of AudioFormat.bytesPerFrameStep, the byte size of one sample across all channels, so a frame boundary never splits a sample.

Additional information

bytesPerFrameFor(format, frameDuration) computes a frame's byte size without needing a PcmFramer instance — handy if something downstream needs to know the number ahead of time.

flush({padWithSilence = true}) takes padWithSilence: false if you'd rather get the raw short remainder back instead of a zero-padded frame, or null if nothing was buffered.

reset() clears buffered partial-frame bytes without emitting them, for reusing a framer across capture sessions.

About

Utility Plugin in the Audio Pipepline to split PCM stream into multiple opus compatible fixed-size frames

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages