Updated on 2025-12-19 GMT+08:00

Audio

Audio data is managed internally with the SoundFile library. Supported audio formats include MP3, AIFF, FLAC, and WAV. The audio object also provides various attributes 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 (e.g., WAV, MP3).

data

bytes

Audio data.

sound_file

sf.SoundFile

Dynamic property: Returns the soundfile library's audio object (auto-decoded from 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 (e.g., WAV to MP3) and returns a new audio object.

write

filename: str

None

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