Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Juan-Carlos-Cruz/robotaxi-zoox/llms.txt

Use this file to discover all available pages before exploring further.

AudioManager manages all audio in Robotaxi Zoox — background ambient music, a looping drive sound during taxi animation, and discrete event effects triggered by pickups, traffic, UI interactions, and route completion. The class wraps pygame.mixer behind a clean interface: when the mixer cannot initialise (headless environments, missing audio device), AudioManager sets enabled = False and every method becomes a silent no-op, so the rest of the application continues unaffected.

Import

from application.audio import AudioManager

Constructor

AudioManager()
Initialises pygame.mixer with frequency=22050, size=-16, channels=2, buffer=512 (if not already running). Allocates 8 mixer channels — channel 1 is reserved for the drive loop, channels 2–3 for round-robin effect playback. Loads all WAV assets from the audio/ directory at the project root. Sets enabled = True on success or enabled = False on any pygame.error, printing a diagnostic message without raising.

Attributes

enabled
bool
True when pygame.mixer initialised successfully and audio is available. False when initialisation failed. All methods check this flag before acting.
ambient_enabled
bool
User-controlled preference for ambient music playback. Defaults to True. Change via set_ambient_enabled().
sounds
dict[str, pygame.mixer.Sound]
Loaded sound effects keyed by internal name: 'road_loop', 'pickup_horn', 'traffic_horn', 'ui_click', 'finish_jingle'. Only populated when enabled is True and the corresponding WAV file exists.

Methods

play_ambient()

audio.play_ambient() -> None
Starts lofi_ambient.wav on the music channel with an infinite loop and a 900 ms fade-in. If ambient music is already playing, it simply updates the volume to match the current drive-loop ducking state. Does nothing when enabled is False or ambient_enabled is False.

start_drive_loop()

audio.start_drive_loop() -> None
Plays road_loop.wav on the dedicated drive channel with an infinite loop and a 250 ms fade-in. Simultaneously ducks the ambient music to DUCKED_AMBIENT_VOLUME (0.16) to keep the soundscape balanced while the taxi is moving. Does nothing when enabled is False or the sound file is missing.

stop_drive_loop()

audio.stop_drive_loop() -> None
Fades out the drive loop over 250 ms and restores ambient music to AMBIENT_VOLUME (0.24). Safe to call even if the drive loop is not currently active. Does nothing when enabled is False.

play_pickup_horn()

audio.play_pickup_horn() -> None
Plays pickup_horn.wav as a one-shot effect on the next available effect channel. Triggered when the taxi collects a passenger.

play_traffic_horn()

audio.play_traffic_horn() -> None
Plays traffic_horn.wav as a one-shot effect. Triggered when the taxi enters a high-traffic cell.

play_ui_click()

audio.play_ui_click() -> None
Plays ui_click.wav as a one-shot effect. Triggered on button presses and algorithm selection changes in the interface.

play_finish_jingle()

audio.play_finish_jingle() -> None
Plays finish_jingle.wav as a one-shot effect. Triggered when the taxi reaches its destination after collecting all passengers.

set_ambient_enabled(enabled)

audio.set_ambient_enabled(enabled: bool) -> None
Toggles ambient music according to the user preference. When set to False, fades out any currently playing music over 250 ms and resets ambient_started. When set to True, immediately calls play_ambient() to begin playback.
enabled
bool
required
True to enable ambient music, False to disable and fade it out.

shutdown()

audio.shutdown() -> None
Gracefully winds down all active sounds: calls stop_drive_loop() to fade out the drive channel, then fades out the music channel over 400 ms. Call this before pygame.quit() to avoid audio artefacts at exit. Does nothing when enabled is False.

Volume constants

All volume values are in the range 0.0 (silent) to 1.0 (full). The constants are defined at module level in application/audio.py.
ConstantValueUsed for
AMBIENT_VOLUME0.24Normal ambient music level
DRIVE_VOLUME0.28road_loop.wav playback volume
PICKUP_HORN_VOLUME0.28pickup_horn.wav effect volume
TRAFFIC_HORN_VOLUME0.24traffic_horn.wav effect volume
UI_CLICK_VOLUME0.22ui_click.wav effect volume
FINISH_JINGLE_VOLUME0.30finish_jingle.wav effect volume
DUCKED_AMBIENT_VOLUME0.16Ambient level while drive loop is active

Example

import pygame
from application.audio import AudioManager

pygame.init()
audio = AudioManager()
if audio.enabled:
    audio.play_ambient()
    audio.start_drive_loop()  # begin taxi movement
    # ... animation ...
    audio.stop_drive_loop()
    audio.play_finish_jingle()
audio.shutdown()
pygame.quit()
All methods are safe to call even when enabled is False — they silently do nothing. There is no need to guard every call site with if audio.enabled; the guard shown in the example above is only necessary when you want to branch on audio availability for other logic.

Build docs developers (and LLMs) love