1

I have a python script that plays a .wav file on the speakers.

from playsound import playsound
playsound('a.wav')

This works correctly if I execute the script on my local machine.

However, if I push the script on my remote Raspberry PI (along with the .wav file) and execute it through an SSH session, the sound doesn't come out of the speaker plugged on the Raspberry PI.

I already had some question related, when I needed to open the web browser on the remote Raspberry PI device, but it doesn't seem to fix it.

I tried

python3 my_script.py

and

DISPLAY=:0 python3 my_script.py

None of them do play the file on the raspberry PI's speakers.

For info, omxplayer a.wav does play the file on the remote speakers properly. But I do not want to call a 'shell' command for that, I'd like this to be done through a python script.

4
  • It seems you don't have a proper Python3 setup on your RPi. – Seamus Oct 3 '20 at 16:13
  • What happens if you put the path to the program before both Python3 and the Python script? – user115418 Oct 3 '20 at 18:55
  • @Seamus Just did a fresh reinstall of Raspbian, with no luck. Andyroo no luck either with that – Arthur Attout Oct 4 '20 at 9:22
  • For the record, Xorg has nothing to do with sound, so adding DISPLAY=:0 to your command will never have an effect on it. – Dmitry Grigoryev Oct 4 '20 at 14:35
1

Ok, it seems the playsound doesn't work properly on Raspbian (tried on a fresh install, with no luck).

However PyDub worked perfectly fine.

2
  • Congratulations, Arthur! +1 Please mark your answer as the "accepted" answer - it's more likely to help others, and you are the ONLY one who can do so. – Seamus Oct 4 '20 at 15:25
  • I'm aware of how Stack Exchange works, however I have to wait until tomorrow to accept my own answer ;-) – Arthur Attout Oct 4 '20 at 17:35

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.