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.

asked Oct 3, 2020 at 15:58
4
  • It seems you don't have a proper Python3 setup on your RPi. Commented Oct 3, 2020 at 16:13
  • What happens if you put the path to the program before both Python3 and the Python script? Commented Oct 3, 2020 at 18:55
  • @Seamus Just did a fresh reinstall of Raspbian, with no luck. Andyroo no luck either with that Commented Oct 4, 2020 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. Commented Oct 4, 2020 at 14:35

1 Answer 1

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.

answered Oct 4, 2020 at 12:03
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. Commented Oct 4, 2020 at 15:25
  • I'm aware of how Stack Exchange works, however I have to wait until tomorrow to accept my own answer ;-) Commented Oct 4, 2020 at 17:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.