Small utility to play a random MP3 from a local sounds/ folder at a random
interval between 30 and 60 seconds. Intended to run on a Raspberry Pi but
works on other Linux/macOS systems too.
Install a system player (recommended) or pygame (fallback).
On Raspberry Pi (Raspbian / Raspberry Pi OS):
sudo apt update
sudo apt install -y mpg123
# optional: sudo apt install -y omxplayer vlcOr install pygame (if you prefer Python playback):
python3 -m pip install --user pygameMake the script executable and run it:
chmod +x play_random_sound.py
./play_random_sound.py --scan
# or explicitly use the built-in SOUND_FILES list
./play_random_sound.py--scan- ignore theSOUND_FILESlist in the script and auto-discover.mp3files insidesounds/.--min Nand--max N- override the minimum and maximum wait intervals (seconds).
- The script prefers system players (mpg123, mpg321, omxplayer, cvlc). If
none are available it attempts to use
pygame.mixeras a fallback. - Stop the script with Ctrl-C.
# Play random sounds discovered in sounds/ with default 30-60s intervals
./play_random_sound.py --scan
# Play using 10-20 second intervals instead (for testing)
./play_random_sound.py --scan --min 10 --max 20- If you see "No valid sound files found" ensure files are named
*.mp3and placed in thesounds/directory next to the script. - If the system player is missing, install
mpg123orvlcor installpygamewith pip.
- Create
/etc/systemd/system/play_random_sound.servicewith the following:
[Unit]
Description=Play random EVE sounds
After=network.target
[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi/path/to/project
ExecStart=/usr/bin/python3 /home/pi/path/to/project/play_eve_sound.py --scan
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal
# Environment=PYTHONUNBUFFERED=1 # optionally useful for immediate logs
[Install]
WantedBy=multi-user.target
- Enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable --now play_random_sound.service