# Struct AudioResource

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

`zaun_client::AudioResource` · Struct

```rust
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.

## Methods

### `ogg`

```rust
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.

### `ogg_file`

```rust
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.

# Errors
`Error::Audio` when the file cannot be opened.

### `opus_packets`

```rust
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).

### `ffmpeg_file`

```rust
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.

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

### `ffmpeg_url`

```rust
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.

### `ffmpeg_reader`

```rust
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.

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

### `pcm`

```rust
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.

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

### `file`

```rust
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.

# Errors
As `ogg_file` and `ffmpeg_file`.

### `with_title`

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

Names the resource (the events carry it).

### `title`

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

The title, if any.

## Trait implementations

`Debug`, `Drop`

[Full rustdoc page](/docs/api/rust/zaun-client/zaun_client/voice/player/struct.AudioResource.html)
