I am very new to Python and Raspberry Pi. I want to write a very simple code that plays a sound effect on my Rasp Pi Zero fitted with a audio amp shim. I have downloaded Python3 Mopidy-MPD using pip. I have edited the Mopidy file to ensure MPD reads enabled=true and has a username of ::. I have edited the boot file to put a # in front of dtparam=audio=on and confirmed that the following have been set dtoverlay=hifiberry-dac and gpio =25=op,dh.
I have a sound effect file in /home/pi/Documents/file.mp3. I have written the following code:
- from mpd import MPDClient
- client.connect (“localhost”,6600)
- print (client.status())
- print (client.mpd_version)
This gives me details of the status and an MPD version number of 0.19.0 hence would suggest that MPD is set up correctly. HOWEVER even reading the MPD documentation I have no idea how I should add the sound effect mentioned to a play list and play the sound. This would seem to be about the simplest use of MPD possible and it is not clear how to do this.
If I try and add a file to a playlist and try and play it:
I get the following error messages:
File “/home/pi/Documents/play.py”, line 6, in
File “/usr/lib/python3-dist-packages/mpd/base.py”, line 381, in mpd_command
return wrapper (self, name, args, callback)
File “/usr/lib/python3-dist-packages/mpd/base.py”, line 473, in _execute
If it’s not possible to use MPD in this way then playsound would also fit my bill. However with playsound installed with pip3 and showing up as playsound 1.2.2 the program
- from playsound import playsound
- playsound (file.mp3)
seems to run OK but doesn’t give out any sound.