Derby Makers

The heart of Derby's Maker community

HifiBerry MiniAmp and speech synthesis

A while back HifiBerry gave us a MiniAmp to play with – thanks guys! We wanted to use it for something in the Silk Mill, but as playing music in there isn’t really on (at least in the normal course of events) we needed to find something else. One idea was something to speak a bit about the things in the Maker Cabinet, but we’ll save that for another article. This one is a quick intro to the MiniAmp, and the trickier parts of using it with text to speech engines like festival.

What is it and how do I connect it?

The MiniAmp is a combined DAC and 3W Class D stereo amplifier. The footprint matches the Pi Zero, but you can just as well use it on the full size boards. This makes it ideal for things like internet radios, but not for something like a full blown hifi setup. Installation is a simple matter of pressing it onto the pin headers, and attaching speakers to the terminals. I used a Pi 3 and a pair of small speakers from some old car phone hands free kits.

Quick test as a media player

I’ve used piCorePlayer before, and it’s supposed to support the HifiBerry boards, so it seemed an ideal first test. I downloaded version 3.11 from the download page, copied to a MicroSD card, connected a network cable to the Pi and booted. The howto page explains the process. By default piCorePlayer uses the onboard mini-jack for output, so you need to go to the ‘Squeezelite settings’ tab and select ‘HifiBerry DAC+ Lite’ in the ‘Audio Output’ dropdown and save. After saving the setting changes it’ll prompt you to reboot the Pi. Once rebooted it played through the speakers, exactly as expected. In this case the speakers are the limiting factor on sound quality. They won’ t be winning any awards, but they’ll be fine for playing a voice.

Setting up with Raspbian

I started with the Raspbian Jessie Lite image since I wasn’t intending to use a GUI, and it’s a smaller download. The configuration starts off quite easily following these instructions. It’s easy to miss the bit about aplay not converting to formats natively supported by the driver though, which is a problem if you try testing with something like:

aplay /usr/share/sounds/alsa/Front_Left.wav

This won’t work and neither will the usual speaker-test program, because the files are mono. Instead you’ll see an error message something like:

Playing WAVE 'usr/share/sounds/alsa/Front_Left.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
aplay: set_params:1297: Unable to install hw params:

It also won’t work with text-to-speech programs like festival and espeak as they use mono. If you’ve dealt with linux audio before you’ll know that usually ALSA (the sound system) takes care of converting the supplied audio to a format that the driver can accept.

As is usually the case someone’s run into this before. It turns out that memory mapping is required by the plugins in ALSA that do the format conversion. This isn’t usually something you need to enable separately, hence the confusion. The fix is easy when you know how – just add another line to /boot/config.txt so you end up with something like:


As before you’ll need to reboot for these to take effect.

The speech bit

Pick your speech engine, install it and test it. I’ve tried festival and espeak so far. Something like:

sudo apt install espeak
espeak 'your text here'

It should now speak to you.

Comments are closed.