Skip to content

~.file

File Audio Source

FileAudioSource

FileAudioSource(
    filepath: str,
    duration: float | None = None,
    *,
    bitrate: str | None = None,
    channels: int | None = None,
    name: str | None = None,
    volume: float | str | None = None
)

Bases: AudioSource

File audio source implementation.

Warning

This source is intended primarily for testing, development, and simple use cases. For production, URL-based or other sources are recommended. Some fields and properties cannot be reliably retrieved without excessive dependencies.

Create a file audio source.

PARAMETER DESCRIPTION
filepath

The filepath to the audio file.

TYPE: str

duration

If provided, the duration of this source - Required if using player timestamp properties/fields.

TYPE: float | None DEFAULT: None

bitrate

If provided, the bitrate in which to play this source back at.

TYPE: str | None DEFAULT: None

channels

If provided, the amount of channels this source plays with.

TYPE: int | None DEFAULT: None

name

If provided, an internal name used for display purposes.

TYPE: str | None DEFAULT: None

volume

If provided, overrides the player's set/default volume. Can be scaled (0.5, 1.0, 2.0, etc.) or dB-based (-3dB, etc.).

TYPE: float | str | None DEFAULT: None

Warning

This source is intended primarily for testing, development, and simple use cases. For production, URL-based or other sources are recommended. Some fields and properties cannot be reliably retrieved without excessive dependencies.

RAISES DESCRIPTION
TypeError
  • If filepath is not str.
  • If duration is provided and not float.
  • If bitrate is provided and not str.
  • If channels is provided and not int.
  • If name is provided and not str.
  • If volume is provided and not float or str.
ValueError
  • If filepath is empty or is not found as a file on the system.
  • If duration is provided and is not greater than 0.
  • If bitrate is provided, and is not between 6k and 510k.
  • If channels is provided and not 1 or 2.
  • If name is provided and is empty.
  • If volume is provided and is either a float and is not positive or a str and does not end with dB, contain a number, or (if provided) doesn't begin with - or +.

filepath property

filepath: str

The filepath to the audio file

bitrate property

bitrate: str | None

If provided, the bitrate in which this source is played back at.

channels property

channels: int | None

If provided, the amount of channels this source plays with.

duration property

duration: float | None

The duration of the source, if provided/found.

name property

name: str | None

If provided, the name assigned to this source for display purposes.

volume property

volume: float | str | None

If provided, the overriding volume for this source.