Silicon Chip – July 2019

(Frankie) #1

siliconchip.com.au Australia’s electronics magazine July 2019 51


Other parameters such as reading speed, voice pitch and
volume can also be adjusted similarly. See the output of
the “help” command mentioned above.


Playing MP3 files and internet radio


As we noted earlier, you can also use “madplay” to
play MP3s or internet radio streams. Using this software
is straightforward.
For example, issuing the command:


madplay file.mp3


will play the “file.mp3” track, assuming it is located in
the current directory of the Pi. If the file name has spaces
or other special characters in it, put the name in quotes
(single or double). You can issue this command:


madplay - -help


to list the command line parameters which madplay
accepts.
To play an internet radio stream, you will need a version
of the Pi with WiFi, and that WiFi needs to be configured
to connect to the internet via your router.
For this task, we’re combining two Linux commands: the
aforementioned madplay, to play the audio, plus a pack-
age called “wget”, which downloads the audio stream over
the internet.
These are combined in a single command, with the con-
tent of the stream being piped by the wget command from
its source URL to the input of madplay. The stream will
continue unless there is an error, or it can be stopped early
by pressing Ctrl-C. For example:


wget -O - “http://us5.internet-radio.com:8487/
| madplay -


It isn’t always obvious what the URL is for the actual ra-
dio stream, as you’re expected to use an online directory
to find and play the streams.


We found it useful to visit http://www.internet-radio.com and
then opening up each .m3u file in a text editor (eg, note-
pad) to determine each station’s stream URL.
Putting this URL into the above command should then
allow you to play that station using the Pi.

Controlling this all automatically
Our final goal was to be able to use the Arduino board
to control the Speech Synthesiser and audio playback
automatically. To this end, we’ve created a basic sample
sketch which communicates with the Pi, including the
login process.
Any text sent to the Arduino over the regular serial
monitor is then sent to the Pi as a command, to be spoken.
Note though that if the Pi is still booting when you send
the text, you will have to wait for it to finish before hear-
ing it spoken.
The sample sketch is called “Pi_TTS_Interface” and is
again available for download from our website. Upload
this to the Leonardo board using the usual procedure and
open a serial terminal or the serial monitor.
The sketch will report on its status and prompt for text
to be spoken when ready. An example of the output of this
sketch is shown in Fig.5.
You can use this sketch as a starting point for your own
voice control schemes. As the cliche says: the sky is the
limit!

What else can you do?
As a small computer in its own right, the Pi is capable
of much more than what we’ve outlined here, especially
the versions equipped with WiFi such as the Pi Zero W.
There’s a lot of information available on the internet on
how to program the Raspberry Pi, so if you’re keen to make
yours do more, head over to your favourite search engine
and start investigating the possibilities. You’ll learn a lot
more by “doing” than by “reading!”

Fig.5 (above): our sample program logins into the Pi’s
console and then sends commands to speak whatever
is typed into the serial monitor. When the “Ready: type
speech” prompt appears, it is ready for speech synthesis.


Fig.6 (right): some files on the microSD card for the Pi can
be edited on a PC as the “boot” volume uses the common
FAT file system. This is much easier to do than using the
Pi’s inbuilt text editor. The “config.txt” file contains many
settings, including which services are started at boot time.


SC
Free download pdf