Skip to main content

AudioResource

Struct AudioResource 

Source
pub struct AudioResource { /* private fields */ }
Expand description

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

Implementations§

Source§

impl AudioResource

Source

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

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

Source

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

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

§Errors

Error::Audio when the file cannot be opened.

Source

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

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

Source

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

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

§Errors

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

Source

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

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

§Errors

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

Source

pub fn ffmpeg_reader( 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.

§Errors

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

Source

pub fn pcm( 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.

§Errors

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

Source

pub fn file(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.

§Errors

As ogg_file and ffmpeg_file.

Source

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

Names the resource (the events carry it).

Source

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

The title, if any.

Trait Implementations§

Source§

impl Debug for AudioResource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for AudioResource

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more