Skip to content

Struct AudioResource

zaun_client::AudioResource · Struct

pub struct AudioResource { … }

Something to play: Opus packets, from an Ogg Opus file or stream, from ffmpeg (any format it reads), or from the application.

pub fn ogg<impl Read + Send + 'static>(reader: impl Read + Send + 'static) -> Self

An Ogg Opus stream (.opus, or .ogg holding Opus), sent as it is.

pub fn ogg_file<impl AsRef<Path>>(path: impl AsRef<Path>) -> Result<Self>

An Ogg Opus file, sent as it is; titled with its file name.

Error::Audio when the file cannot be opened.

pub fn opus_packets<impl IntoIterator<Item = Vec<u8>, IntoIter : Send + 'static>>(packets: impl IntoIterator<Item = Vec<u8>, IntoIter = …>) -> Self

Opus packets the application made (each one 2.5 to 120 ms, as its TOC byte says).

pub fn ffmpeg_file<impl AsRef<Path>>(path: impl AsRef<Path>, options: FfmpegOptions) -> Result<Self>

Any audio file ffmpeg reads (mp3, flac, wav, m4a, a video’s sound…), transcoded to Opus.

Error::Audio when the file is missing, an option is out of range, or ffmpeg is not installed.

pub fn ffmpeg_url(url: &str, options: FfmpegOptions) -> Result<Self>

An http:// or https:// stream or file, fetched and transcoded by ffmpeg.

Error::Audio for another scheme, an option out of range, or no ffmpeg.

pub fn ffmpeg_reader<impl Read + Send + 'static>(reader: impl Read + Send + 'static, options: FfmpegOptions) -> Result<Self>

Audio the application streams (another program’s output, a download), transcoded by ffmpeg as it arrives.

Error::Audio for an option out of range, or no ffmpeg.

pub fn pcm<impl Read + Send + 'static>(reader: impl Read + Send + 'static, options: FfmpegOptions) -> Result<Self>

Raw PCM the application makes (text to speech, a synthesiser): signed 16-bit little-endian samples, 48 kHz, two channels interleaved. Encoded to Opus by ffmpeg.

Error::Audio for an option out of range, or no ffmpeg.

pub fn file<impl AsRef<Path>>(path: impl AsRef<Path>, options: FfmpegOptions) -> Result<Self>

Any audio file: an Ogg Opus file is sent as it is (no ffmpeg, no quality lost, like discord.js’s demuxProbe), anything else goes through ffmpeg. options apply only when ffmpeg runs; a volume or seek asks for it even for Ogg Opus.

As ogg_file and ffmpeg_file.

pub fn with_title<impl Into<String>>(self, title: impl Into<String>) -> Self

Names the resource (the events carry it).

pub fn title(&self) -> Option<&str>

The title, if any.

Debug, Drop

Full rustdoc page