# Struct Voice

> The bot's voice: one stay at a time.

`zaun_bot::Voice` · Struct

```rust
pub struct Voice
```

The bot's voice: one stay at a time.

## Methods

### `seek`

```rust
pub fn seek(ms: u64) -> Result<(), HostError>
```

Jumps to `ms` into the current track; past the end, the track ends.

# Errors
`UNSUPPORTED` for live streams and pushed audio, and on hosts that cannot seek;
`CONFLICT` when nothing plays.

### `set_volume`

```rust
pub fn set_volume(percent: u16) -> Result<(), HostError>
```

Sets the playback volume, 0–200 % (100 when the bot joins).

# Errors
`BAD_REQUEST` (detail `percent`) above 200, checked before the call; `UNSUPPORTED` on
hosts without an Opus encoder, which is most of them for now: tell the member and go on.

### `remove`

```rust
pub fn remove(index: u32) -> Result<Option<String>, HostError>
```

Removes the queued track at `index` (0 plays next); returns its title.

# Errors
`NOT_FOUND` past the end of the queue; `UNSUPPORTED` on hosts without queue control.

### `move_track`

```rust
pub fn move_track(from: u32, to: u32) -> Result<(), HostError>
```

Moves the queued track at `from` to `to` (both 0-based); the tracks between shift.

# Errors
`NOT_FOUND` past the end of the queue; `UNSUPPORTED` on hosts without queue control.

### `shuffle`

```rust
pub fn shuffle() -> Result<(), HostError>
```

Puts the queue in a random order; the current track keeps playing.

# Errors
`UNSUPPORTED` on hosts without queue control.

### `clear_queue`

```rust
pub fn clear_queue() -> Result<(), HostError>
```

Empties the queue; unlike `Voice::stop`, the current track keeps playing.

# Errors
`UNSUPPORTED` on hosts without queue control.

### `set_loop`

```rust
pub fn set_loop(mode: LoopMode) -> Result<(), HostError>
```

Sets what happens when a track ends: go on, repeat it, or requeue it at the end.

# Errors
`UNSUPPORTED` on hosts without looping.

### `join`

```rust
pub fn join(channel: &str) -> Result<(), HostError>
```

Joins voice channel `channel` (leaving another one); returns once audio can flow.

# Errors
`NOT_GRANTED` without the `voice` capability; `FORBIDDEN` without `CONNECT`/`SPEAK`.

### `leave`

```rust
pub fn leave()
```

Leaves; playback stops and the queue is cleared.

### `play_url`

```rust
pub fn play_url(url: &str, title: Option<&str>) -> Result<(), HostError>
```

Plays an Ogg Opus file or stream now, replacing the current track: an `https://` URL
on a `network` host, or an `http://`/`https://` URL on a `local_network` address. The
SDK passes the URL through; the host checks it.

# Errors
`CONFLICT` when not in a voice channel; an address outside the grants shows up as a
`TrackError` event when the track starts.

### `enqueue_url`

```rust
pub fn enqueue_url(url: &str, title: Option<&str>) -> Result<u32, HostError>
```

Queues an Ogg Opus file or stream (as `Voice::play_url`); returns the queue's length.

# Errors
As `Voice::play_url`; `CONFLICT` with `limit_reached` past 100 tracks.

### `play_ogg`

```rust
pub fn play_ogg(bytes: Vec<u8>, title: Option<&str>) -> Result<(), HostError>
```

Plays Ogg Opus bytes (≤ 16 MiB) now.

# Errors
As `Voice::play_url`.

### `start_stream`

```rust
pub fn start_stream(title: Option<&str>) -> Result<(), HostError>
```

Starts a track the bot feeds with `Voice::push_opus` until `Voice::end_stream`.

# Errors
As `Voice::play_url`.

### `push_opus`

```rust
pub fn push_opus(packets: &[Vec<u8>]) -> Result<u32, HostError>
```

Opus packets (2.5–120 ms each, ≤ 1000 bytes) for the current stream; returns the ms
buffered. Push about as fast as it plays.

# Errors
`BUSY` past 3 s buffered (push again later); `CONFLICT` without a stream track.

### `end_stream`

```rust
pub fn end_stream()
```

Ends the stream track once its buffered packets have played.

### `skip`

```rust
pub fn skip()
```

Ends the current track; the next queued one starts.

### `stop`

```rust
pub fn stop()
```

Ends the current track and clears the queue.

### `pause`

```rust
pub fn pause()
```

Pauses.

### `resume`

```rust
pub fn resume()
```

Resumes.

### `state`

```rust
pub fn state() -> VoiceState
```

Where the bot is and what it plays.

## Trait implementations

`Clone`, `Copy`, `Debug`, `Default`

[Full rustdoc page](/docs/api/rust/zaun-bot/zaun_bot/voice/struct.Voice.html)
