/ogg-opus

Primary LanguageRust

Ogg Opus

A decoder/encoder for Ogg Opus in Rust

Usage

Add to your cargo.toml

ogg-opus = "^0.1"

Minimum Rust version

Since we use const generics, the minimum version of Rust is 1.51

Example

Encode

This example makes use of wav crate, you can use it adding to your cargo.toml file:

wav = "^1.0"
let mut f = File::open("my_file.wav").unwrap();
let (_, b) = wav::read(&mut f).unwrap();
let audio = b.try_into_sixteen().unwrap();
let opus = ogg_opus::encode::<16000, 1>(&audio).unwrap();

Decode

Read from file

let mut f = File::open("my_file.ogg").unwrap();
let (raw, header) = ogg_opus::decode::<_,16000>(f).unwrap();

Read from Vec

use std::io::Cursor;

// Let's say this vec contains Ogg Opus data
let opus: Vec<u8> = Vec::new();
let (raw, header) = ogg_opus::decode::<_,16000>(Cursor::new(opus)).unwrap();

What works and what not

  • Only supports i16 (integer of 16 bits) for the raw part.
  • Both mono and stereo are supported but only mono is tested.
  • More channels than stereo are untested and will probably break it.
  • Supports decoding and encoding any sample rate supported by Opus (8k Hz, 12k Hz, 24k Hz and 64k Hz) but only 16k Hz has been tested
  • Encoding is set to a bitrate of 24k (because of Lily's constraints)
  • There's still some inaccuracies around start and end of audio (can't tell if it's due to the encoder or the decoder)
  • Advanced decode and encoding features (repairables streams, fec and others)