Using Pirate Audio to programmatically play an mp3?

Hi, I’ve learned the hard way that plugging a small amplifier into the headphone jack and playing an MP3 picks up a huge amount of RF noise from my robot and also just sounds terrible (it’s a headphone jack so it doesn’t have the right impedance, I clearly need a line out). I’m thinking of buying a Pirate Audio: Line-out for Raspberry Pi and plugging its output into the Adafruit 2.5W mono amplifier I’ve already got. So, two questions:

  1. I could certainly use the Pirate Audio as intended as a media player but I’m wondering if there’s some way to simply play an existing mp3 file, called from a Python program. I’m interested in having my robot make high quality sounds. I couldn’t find anything in the github examples except code to control the display. Is there anything in Python to send an mp3 to the output, and control its volume and playback? Or is the only way to use Mopidy’s UI?

  2. if my Adafruit amp is monophonic (and I only have one small speaker on my robot), is there an safe way to get the stereo output on the Pirate Audio into the mono inputs of the amp, or should I just mix down all of my MP3s to use just
    one of the two channels? (i.e,. cheat).

Thanks!

To my knowledge Pirate Audio really just outputs the Pi’s sytem audio, so any Python system for playing audio should work. Try something like this.

I’m not sure about the second part, it might be possible to get AlsaMixer to do that for you?

Hi, I’ve currently got a Python class called Player that outputs one of an enumerated set of MP3 files, so it sounds like Pirate Audio would work transparently with that. As for AlsaMixer, I’m familiar with it from Ubuntu Linux so I can give that a try (though I thought it was only used as a UI). I guess I could use it by booting the robot with a monitor attached to set to mono, then go back to CLI for normal use. I’ll investigate.

Thanks for the quick response.