當透過 Pi 上的 systemd 啟動時,Pygame 音訊充滿了爆裂聲/劈啪聲

當透過 Pi 上的 systemd 啟動時,Pygame 音訊充滿了爆裂聲/劈啪聲

我正在嘗試設定一個播放音訊的 Python 進程,以便使用 systemd 在啟動時自動啟動,但是當我這樣做時,音訊充滿了流行音樂,即使當我自己在命令列中運行它時也沒有問題。正如您在下面的文件中看到的,.service我嘗試以我能想到的各種方式最大化進程優先順序。有人知道出了什麼問題嗎?

腳本在這裡:https://github.com/UndarkAido/superhet(您必須填充該music目錄並secrets.py自行運行它。genBreaks.py填充該breaks目錄。)

超級服務:

[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

系統資訊:

  `.::///+:/-.        --///+//-:``    -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
 .::` .:::::::::- `::::::::::``::.
-:::` ::::::::::.  ::::::::::.`:::-
::::  -::::::::.   `-::::::::  ::::
-::-   .-:::-.``....``.-::-.   -::-
 .. ``       .::::::::.     `..`..
   -:::-`   -::::::::::`  .:::::`
   :::::::` -::::::::::` :::::::.
   .:::::::  -::::::::. ::::::::
    `-:::::`   ..--.`   ::::::.
      `...`  `...--..`  `...`
            .::::::::::
             `.-::::-`

編輯:也定期systemctl status superhet.service顯示superhet python[1040]: ALSA lib pcm.c:8424:(snd_pcm_recover) underrun occurred

答案1

新增Environment=XDG_RUNTIME_DIR=/run/user/1000至服務檔案允許 PyGame 連接到 PulseAudio

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

相關內容