Skip to content

feat: support multiple audio formats and load alarm files dynamically - #1

Open
422August wants to merge 1 commit into
294Ryan:mainfrom
422August:main
Open

feat: support multiple audio formats and load alarm files dynamically#1
422August wants to merge 1 commit into
294Ryan:mainfrom
422August:main

Conversation

@422August

@422August 422August commented Aug 10, 2026

Copy link
Copy Markdown

Description

Background & Purpose

Previously, the application hardcoded the alarm sound file to .wav and resolved the file path only once upon application launch. To improve flexibility, this PR expands audio format compatibility and switches to dynamic file discovery whenever the alarm triggers.

Key Changes

  • Expanded Audio Format Support: Added support for .mp3, .ogg, and .flac formats via SUPPORTED_FORMATS = (".mp3", ".wav", ".ogg", ".flac").
  • Deterministic File Resolution: Added sorted() in get_alarm_path() to ensure a predictable file loading order when multiple audio files exist.
  • Dynamic Alarm Loading: Moved the get_alarm_path() resolution inside _startAlarm(). Replacing or adding audio files while the application is running takes effect immediately without needing a restart.

Code Diff Summary

# Added supported formats and dynamic discovery logic
SUPPORTED_FORMATS = (".mp3", ".wav", ".ogg", ".flac")

def get_alarm_path():
    if os.path.exists(ALARM_DIR):
        for file in sorted(os.listdir(ALARM_DIR)):
            if file.lower().endswith(SUPPORTED_FORMATS):
                return os.path.join(ALARM_DIR, file)
    return os.path.join(ALARM_DIR, "alarm.wav")

# _startAlarm now retrieves the latest path dynamically
def _startAlarm(self):
    alarm_path = get_alarm_path()
    if not os.path.exists(alarm_path):
        print(f"[Warning] Alarm file not found: {alarm_path}")
        return
    # ... playback logic ...

Verification & Testing

  • Multi-format Verification: Tested .mp3 and .ogg files in the alarm/ directory; both play as expected.
  • Hot-Swapping: Replaced audio files in alarm/ while the app was running; the new audio played successfully on the next alarm trigger.
  • Fallback Handling: Verified that missing audio files log a warning without crashing the UI.

@422August

Copy link
Copy Markdown
Author

@294Ryan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant