Dexter Speaks
Written and filmed by Haddington Dynamics Technical Evangelist James Newton
Since there is no actual connection to audio on the MicroZed board, an external USB audio adapter is probably the best way to help Dexter find it's voice... and possibly it's ears. Dexter does have 1 onboard USB port, just under the CAT5 network connector on the bottom.
If you have multiple USB devices to connect, a small USB hub, like this one for the RasPi Zero, is a great fit: https://www.adafruit.com/product/4115
Or you can just plug the USB audio adapter in directly.
This device was tested: https://www.amazon.com/dp/B01J7P0OGI, and it works, but requires an external amplifier, speakers, and mic which can be difficult to mount.
If all we want is output, this all-in-one USB sound adapter, amplifier and speaker is excellent. The only disadvantage being that there is no physical volume control (see notes on amixer below):
HONKYOB USB Mini Speaker Computer Speaker Powered Stereo Multimedia Speaker for Notebook Laptop PC(Black): $12.99
Mini External USB Stereo Speaker: $12.50
After connecting, the light on the USB adapter comes on and if we ssh in, a quick
ls /dev/*audio* shows /dev/audio1 so we have a device installed!
Since it shows up as audio1 (vs 0) we need a quick
nano /etc/modprobe.d/alsa-base.conf to change the last line from:
options snd-usb-audio index=-2to
options snd-usb-audio index=0then a restart. Note: Your Dexter image may already have these changes made.
Now,
speaker-testshows we are working! Cool huh? But that's just a recording of a voice, we want to produce arbitrary speech; we need a text to speech synthesizer.
After searching through several open source speech synths, we found that e-speak is light weight, very understandable, and actually sounds pretty darn cool. Check to see if you already have it installed by sshing into Dexter and typing
espeak --helpTo install it, if it isn't already, Dexter needs to be connected to the internet (not just to your pc) and then we can:
apt-get install espeakOnce that finishes,
espeak "Hello"should produce a nice robotic greeting, along with a ton of warning and error messages. After careful investigation, none of those are valid and suppressing them is very difficult. We could just ignore them, but one way to avoid them is to use aplay, which is nice to have anyway. aplay can be used to play back .wav sound files, generate beeps, and even music (https://github.com/JamesNewton/BitShift-Variations-unrolled)
To get aplay to work on audio1, we need to
nano ~/.asoundrcand then replace it with this text:
pcm.!default {
# type hw
# card 0
# on Dexter, we want the default device to be a plug into the hardware
type plug
slave {
pcm "hw:0,0"
}
}
ctl.!default {
type hw
card 0
} Now, we can:
espeak "hello" --stdout | aplayand get a nice sound without a bunch of silly messages.
With a voice, we can edit our startup scripts, network change triggers, or other code to provide status data. To add speech to the onboard "Job Engine" for running DDE jobs on Dexter, see: https://github.com/HaddingtonDynamics/Dexter/issues/72#issuecomment-529731676
WARNING: Be very careful about adding any attempt to speak or play any sound to a script that needs to run on startup. If you don't have a sound card plugged in, that will generate an error, and the error may make the script file. E.g. adding those commands to speak the IP address to RunDexRun then unplugging the adapter will cause the robot to fail to start the DexRun firmware, etc...
This issue can be avoided by using a bash script called that checks to verify the audio device is connected.
#!/bin/sh
if [ -c /dev/audio ]; then
espeak "$@" --stdout | aplay
else
echo no audio adapter found
fi You might call that file
say and don't forget to
chmod +xsay then call it with
./say "hello all!"