Skip to content

zaun_bot::Audio · Struct

pub struct Audio

The bot’s audio output stream.

pub fn open(options: &StreamOptions) -> Result<(), HostError>

Opens the stream with every option.

CONFLICT when the bot is in no voice channel or a stream is open; UNSUPPORTED for a format the host cannot take; BAD_REQUEST for values out of range.

pub fn open_opus(title: Option<&str>) -> Result<(), HostError>

Opens a stream of Opus packets the bot encodes (Audio::write_opus).

As Audio::open.

pub fn open_pcm(sample_rate: u32, channels: u8, title: Option<&str>) -> Result<(), HostError>

Opens a stream of 16-bit PCM (Audio::write_pcm) at sample_rate (8000, 12000, 16000, 24000 or 48000) with 1 or 2 interleaved channels; the host encodes it.

As Audio::open; UNSUPPORTED on hosts without an Opus encoder.

pub fn write_opus(packets: &[Vec<u8>]) -> Result<u32, HostError>

Writes Opus packets (2.5–120 ms each, ≤ 1000 bytes); returns the ms buffered.

BUSY past 3 s buffered (write again on AudioLow); CONFLICT without an opus stream.

pub fn write_pcm(samples: &[i16]) -> Result<u32, HostError>

Writes interleaved samples, any count; returns the ms buffered.

BUSY past 3 s buffered (write again on AudioLow); CONFLICT without a pcm stream.

pub fn buffered_ms() -> u32

The audio written and not yet played, in ms (0 without a stream).

pub fn clear() -> Result<(), HostError>

Drops everything buffered at once; the stream stays open.

CONFLICT without a stream.

pub fn close(drain: bool)

Closes the stream, after the buffer has played (drain) or at once; the player resumes. VoiceEvent::AudioClosed follows.

Clone, Copy, Debug, Default

Full rustdoc page