I am looking for a well maintained python library with allows me to play audio files on my raspberry using the standart audio output. So far I've tried several but none of them seem to work. Although pyglet works on my regular computer fine it causes an error on the raspberry. Is there any python library which has been proven as easy to use?
I recommend the widely popular Pygame. I may be wrong, but I believe that it is pre-installed on the Pi. You can use the Pygame Mixer Music Module to play audio files. I have included some example code below. Assuming that we have an audio file called
NOTE: If this fails, please go to the terminal and update your system with
and try again. |
|||
|
I needed a script to play a song from thirty seconds in in the background whilst responding to other user input. I then wanted it to end the song on some event. I don't suppose it's particularly elegant, but I opened a pipe to a background MPlayer process.
Then, when I wanted to terminate the MPlayer process, I simply wrote "q" for quit to the pipe.
Look at MPlayer documentation for all sorts of commands you can pass in this way to control playback. Hopefully that's somewhat helpful! |
|||
|
Another option is to use
then in python:
Pygame is almost certainly more robust, but it depends I suppose on what your needs are. |
||||
|