0

I'm trying to set up a Python process that plays audio to auromatically start on boot with systemd but when I do the audio is full of pops, even though it's fine when I run it myself in the command line. As you can see in my .service file below I've tried maxing out the process priority in every way I can think of. Does anyone know what's going wrong?

The script is here: https://github.com/UndarkAido/superhet (You'll have to populate the music directory and secrets.py yourself to run it. genBreaks.py populates the breaks directory.)

superhet.service:

[Unit]
 Description=Superhet radio
 After=multi-user.target sound.target

 [Service]
 Type=simple
 CPUSchedulingPolicy=fifo
 CPUSchedulingPriority=99
 IOSchedulingClass=realtime
 IOSchedulingPriority=0
 Nice=-20
 User=aidan
 Group=aidan
 WorkingDirectory=/home/-user-/Source/superhet
 ExecStart=/home/-user-/Source/superhet/venv/bin/python main.py

 [Install]
 WantedBy=multi-user.target

System info:

  `.::///+:/-.        --///+//-:``    -user-@superhet
 `+oooooooooooo:   `+oooooooooooo:    --------------
  /oooo++//ooooo:  ooooo+//+ooooo.    OS: Raspbian GNU/Linux 10 (buster) armv7l
  `+ooooooo:-:oo-  +o+::/ooooooo:     Host: Raspberry Pi 4 Model B Rev 1.1
   `:oooooooo+``    `.oooooooo+-      Kernel: 5.10.63-v7l+
     `:++ooo/.        :+ooo+/.`       Uptime: 20 mins
        ...`  `.----.` ``..           Packages: 1485 (dpkg)
     .::::-``:::::::::.`-:::-`        Shell: bash 5.0.3
    -:::-`   .:::::::-`  `-:::-       Terminal: /dev/pts/0
   `::.  `.--.`  `` `.---.``.::`      CPU: BCM2711 (4) @ 1.500GHz
       .::::::::`  -::::::::` `       Memory: 89MiB / 1872MiB
 .::` .:::::::::- `::::::::::``::.
-:::` ::::::::::.  ::::::::::.`:::-
::::  -::::::::.   `-::::::::  ::::
-::-   .-:::-.``....``.-::-.   -::-
 .. ``       .::::::::.     `..`..
   -:::-`   -::::::::::`  .:::::`
   :::::::` -::::::::::` :::::::.
   .:::::::  -::::::::. ::::::::
    `-:::::`   ..--.`   ::::::.
      `...`  `...--..`  `...`
            .::::::::::
             `.-::::-`

Edit: systemctl status superhet.service also shows superhet python[1040]: ALSA lib pcm.c:8424:(snd_pcm_recover) underrun occurred periodically

Aido
  • 166
  • 14

1 Answers1

0

Adding Environment=XDG_RUNTIME_DIR=/run/user/1000 to the service file allowed PyGame to connect to PulseAudio

https://stackoverflow.com/q/49059610/1526048

Aido
  • 166
  • 14