brian.audio
- PlaybackMode
- AudioFileMetadata
- PlaybackStatus
- play_tone
- stop_tone
- play_file
- stop_playback
- get_playback_status
- wait_until_done_playing
PlaybackMode class objects
Mirrors AudioDriver::PlaybackMode (values match firmware).
IDLE
Nothing is playing
TONE
A tone started by play_tone() is playing
FILE_STREAM
A file started by play_file() is playing
AudioFileMetadata class objects
Read-only snapshot of file metadata (attrtuple at runtime).
Use attribute access: channels, bits_per_sample, sample_rate_hz, total_samples, is_supported_format.
channels
Number of audio channels
bits_per_sample
Bits per sample of one channel
sample_rate_hz
Sample rate in Hz
total_samples
Length of the file in sample frames (one frame holds a sample of every channel)
is_supported_format
True if Brian can play this file format
PlaybackStatus class objects
Read-only playback snapshot (attrtuple at runtime).
Use attribute access: mode, has_ended, current_sample, metadata.
mode
What is currently playing
has_ended
True once the playback has finished
current_sample
Index of the sample frame being played
metadata
Metadata of the file being played
play_tone
Play a sine tone to the audio output.
This method returns instantly and the tone is played in the background.
Arguments:
tone: Frequency in Hz to play.duration_ms: How long should the tone last
stop_tone
play_file
def play_file(path: str,
*,
skip_samples: Optional[int] = None,
adaptive_loudness: Optional[bool] = None) -> bool
Stream and play an audio file from SD card.
The file is decoded and pushed in chunks and is not loaded fully to memory.
Arguments:
path: Absolute VFS path to file (for example/recording.wav).skip_samples: IfNone, start from the beginning of the file. If set, number of source sample frames to skip before playback (per-channel frames in the WAV; same meaning asAudioDriver::playAudioFile). Must be non-negative. Very large integers may raiseOverflowErroron the firmware port.adaptive_loudness: IfTrue, apply slow AGC, gentle compression, and limiting. IfNone, the firmware default (enabled) is used.
Returns:
True if playback request was accepted, False otherwise.
stop_playback
get_playback_status
Return a snapshot of current playback state, or None if status is unavailable.
The returned object supports attribute access like PlaybackStatus / AudioFileMetadata
(implementation uses compact read-only attrtuples).
wait_until_done_playing
Block until no tone or file stream is active, timeout_ms elapses, or the program is stopped/interrupted.
Arguments:
timeout_ms: Maximum wait in milliseconds;Nonemeans wait until idle or abort.
Returns:
True if playback became idle; False on timeout or abort.