Struct Audio
zaun_bot::Audio · Struct
pub struct AudioThe bot’s audio output stream.
Methods
Section titled “Methods”pub fn open(options: &StreamOptions) -> Result<(), HostError>Opens the stream with every option.
Errors
Section titled “Errors”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.
open_opus
Section titled “open_opus”pub fn open_opus(title: Option<&str>) -> Result<(), HostError>Opens a stream of Opus packets the bot encodes (Audio::write_opus).
Errors
Section titled “Errors”As Audio::open.
open_pcm
Section titled “open_pcm”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.
Errors
Section titled “Errors”As Audio::open; UNSUPPORTED on hosts without an Opus encoder.
write_opus
Section titled “write_opus”pub fn write_opus(packets: &[Vec<u8>]) -> Result<u32, HostError>Writes Opus packets (2.5–120 ms each, ≤ 1000 bytes); returns the ms buffered.
Errors
Section titled “Errors”BUSY past 3 s buffered (write again on AudioLow); CONFLICT without an opus
stream.
write_pcm
Section titled “write_pcm”pub fn write_pcm(samples: &[i16]) -> Result<u32, HostError>Writes interleaved samples, any count; returns the ms buffered.
Errors
Section titled “Errors”BUSY past 3 s buffered (write again on AudioLow); CONFLICT without a pcm
stream.
buffered_ms
Section titled “buffered_ms”pub fn buffered_ms() -> u32The 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.
Errors
Section titled “Errors”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.
Trait implementations
Section titled “Trait implementations”Clone, Copy, Debug, Default