0

After trying every possible solution online I am posting this question. I have a python script that runs on boot with the help of systemd. Everything worked fine till I installed a fresh raspian buster. Now I am able to run the python program via both systemd and through Thonny Editor. But the difference is that systemd doesn't give any audio output while the editor does. I tried to run my python script via terminal and the audio was playing without any issues.

Now please note that I have another raspberry pi which is still running the older version of the OS with the same systemd configuration and everything works fine in it. Now I could have easily cloned that sd card and used it but that sd card is 16 GB and I want to migrate to a 32 GB sd card(I tried cloning, pi didn't boot up)

This is the systemd service file

[Unit]
Description=My Service
After=network.target

[Service]
ExecStart=/usr/bin/python3 -u Main.py
WorkingDirectory= /home/pi/xyz
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi


[Install]
WantedBy = default.target

Systemd runs the python file without any errors but with no audio output. Please help me out.

6
  • What does the script do? Does it endless play a sound in the background? Do you use pulseaudio?
    – Ingo
    Jan 10 at 18:44
  • @Ingo The script plays a welcome sound when started and then will play sound whenever the push buttons are clicked. Very basic stuff. Jan 11 at 2:26
  • 1
    I am having the same problem exactly. Was a solution ever found? I can get it to work via a .desktop file, but I'd really like to use functionality of systemd. May 19 at 20:16
  • @PeterWiley No solution was found. I had to shift to the older version of Raspian OS. Because after updating this problem started for me. May 20 at 8:10
  • @PeterWiley solution has been given in this thread. Please check May 21 at 8:18
1

The answer to this issue can be found here:

https://www.raspberrypi.org/forums/viewtopic.php?t=278665

The solution presented worked for me to get sound while running a python program from system.

What one has to do is to add defaults to the asound.conf file at /etc/asound.conf. I did sudo nano on file and found nothing in it, so I added

   defaults.pcm.card 1
   defaults.pcm.card 1

Why "1"? It's the number given when one does

    pi@xxxx:~ $ cat /proc/asound/cards
    0 [b1             ]: bcm2835_hdmi - bcm2835 HDMI 1
                  bcm2835 HDMI 1
    1 [Headphones     ]: bcm2835_headphonbcm2835 Headphones - bcm2835 Headphones
                  bcm2835 Headphones

In my case I wanted sound out of the headphone jack.

1
  • Thank you so much for the answer. May 21 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.