Skip to content

brian.audio

brian

PlaybackMode class objects

class PlaybackMode(Enum)

Mirrors AudioDriver::PlaybackMode (values match firmware).

IDLE

TONE

FILE_STREAM

AudioFileMetadata class objects

class AudioFileMetadata()

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

bits_per_sample

sample_rate_hz

total_samples

is_supported_format

PlaybackStatus class objects

class PlaybackStatus()

Read-only playback snapshot (attrtuple at runtime). Use attribute access: mode, has_ended, current_sample, metadata.

mode

has_ended

current_sample

metadata

play_tone

def play_tone(tone: int, duration_ms: int)

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

def stop_tone()

If tone is playing because of previous call to play_tone, it is stopped early.

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: If None, start from the beginning of the file. If set, number of source sample frames to skip before playback (per-channel frames in the WAV). Must be non-negative. Very large integers may raise OverflowError on the firmware port.
  • adaptive_loudness: If True, apply slow AGC, gentle compression, and limiting. If None, the firmware default (enabled) is used.

Returns:

True if playback request was accepted, False otherwise.

stop_playback

def stop_playback()

Stop currently active tone or file playback.

get_playback_status

def get_playback_status() -> Optional[PlaybackStatus]

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

def wait_until_done_playing(timeout_ms: Optional[float] = None) -> bool

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; None means wait until idle or abort.

Returns:

True if playback became idle; False on timeout or abort.