Updated on 2026-11-06 GMT+08:00

Audio

Audio data is processed internally with the PyAV library. Supported audio formats include MP3, AIFF, FLAC, WAV, WMA, M4A, and AAC. The audio object also provides various properties and methods for manipulation.

Table 1 Properties

Property

Type

Description

filename

str

File name or path of the audio (if loaded from a file).

format

str

Audio format (for example, WAV or MP3).

subtype

str

Audio encoding.

data

bytes

Audio data.

Table 2 Methods

Method

Parameter

Return Value

Description

__init__

filename: Union[str, os.PathLike] = None

data: Union[str, bytes, sf.SoundFile] = None

None

Constructor: Loads audio from a file (filename) or data (data), supporting binary data or soundfile objects.

truncate

start_time: float = 0

end_time: Optional[float] = None

Audio

Extracts a segment of the audio (in seconds) and returns a new audio object.

convert_format

format: str

subtype: Optional[str] = None

Audio

Converts the audio to a specified format (for example, from WAV to MP3) and returns a new audio object.

write

filename: str

None

Saves the audio to the specified file (format is automatically inferred).

split

interval: int

list[Audio]

Splits the audio into a list of segments based on a specified interval (in seconds).