Skip to content

Instantly share code, notes, and snippets.

@davcri
Last active September 28, 2021 09:55
Show Gist options
  • Save davcri/cdcad36403d74793d8339d5dcd0c4d70 to your computer and use it in GitHub Desktop.
Save davcri/cdcad36403d74793d8339d5dcd0c4d70 to your computer and use it in GitHub Desktop.
systemd: create timer to play audio every 5 minutes to prevent speakers auto-suspend
# download python script
wget https://gist.githubusercontent.com/davcri/35074eda17caf24e0d8269edba58192c/raw/514e8c027c46b2f98e6674beb62ec4b3e1b1a346/generate-sine-tone-wav.py
# generate sine tone
python generate-sine-tone-wav.py
# move audio file
mv sine-wave-20hz.wav ~/.local/sine-wave-20hz.wav

Create unit file:

sudo nano /etc/systemd/user/play-audio.service

Copy paste this:

[Unit]
Description=Play low freq and low volume audio to prevent speakers suspend

[Service]
Type=oneshot
ExecStart=paplay /home/dc/.local/output.wav # DOUBLE CHECK THE PATH! Here I used my username "dc"

Create systemd timer:

sudo nano /etc/systemd/user/play-audio.timer

Copy paste this:

[Unit]
Description=Run play-audio service unit

[Timer]
OnBootSec=1min
OnUnitActiveSec=5min

[Install]
WantedBy=timers.target

Finally activate the timer:

systemctl --user enable play-audio.timer
# to check if the timer works:
watch -n 1 journalctl --user -u play-audio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment