pub struct Audio;Expand description
The bot’s audio output stream.
Implementations§
Source§impl Audio
impl Audio
Sourcepub fn open(options: &StreamOptions) -> Result<(), HostError>
pub fn open(options: &StreamOptions) -> Result<(), HostError>
Opens the stream with every option.
§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.
Sourcepub fn open_pcm(
sample_rate: u32,
channels: u8,
title: Option<&str>,
) -> Result<(), HostError>
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
As Audio::open; UNSUPPORTED on hosts without an Opus encoder.
Sourcepub fn write_opus(packets: &[Vec<u8>]) -> Result<u32, HostError>
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
BUSY past 3 s buffered (write again on AudioLow); CONFLICT without an opus
stream.
Sourcepub fn write_pcm(samples: &[i16]) -> Result<u32, HostError>
pub fn write_pcm(samples: &[i16]) -> Result<u32, HostError>
Writes interleaved samples, any count; returns the ms buffered.
§Errors
BUSY past 3 s buffered (write again on AudioLow); CONFLICT without a pcm
stream.
Sourcepub fn buffered_ms() -> u32
pub fn buffered_ms() -> u32
The audio written and not yet played, in ms (0 without a stream).
Sourcepub fn close(drain: bool)
pub fn close(drain: bool)
Closes the stream, after the buffer has played (drain) or at once; the player
resumes. VoiceEvent::AudioClosed follows.