Swiftly and with Style

You Talkin' To Me?

Charles Gamble

I have been having some fun with Picochess lately, I got a little bored of the beeping noises coming from the clock and wanted to see if it would be possible to get some Text-To-Speech audio working on the Raspberry Pi from Picochess. I thought it would be great to hear Picochess announce the moves by speaking them instead of just beeping.

I found three speech engines for the Raspberry Pi:

  • Festival - A classic robotic-sounding voice.
  • Espeak - A more whiny-sounding robotic voice.
  • Cepstral - A commercial TTS engine with a nice fairly natural voice called Callie.

For flexibility I decided to write a framework that could call any command-line speech engine and used config files to define voices and vocabulary. This allows the exact text content to be tuned for each speech engine, as they often pronounce things differently from each other.

Then I integrated this framework into my local copy of Picochess. You can see a video of it in action.

It does add a delay to the playing obviously so it's not for the speed demon players, but it might appeal to anyone just enjoying a leisurely game.

I have been running Picochess on my Fuze machine, which now contains a Raspberry Pi 2 model B! It took all of 2 minutes to swap out the original model B for the faster v2.

You can see my setup below: DGT bluetooth chess board and DGT 3000 chess clock with a Fuze case containing a Raspberry Pi 2

Adding a Speaker to the Raspberry Pi

First I discovered that the Raspberry Pi has an extremely low sound output, so I would need some kind of amplification to be able to hear the speech. I could have used some external powered speakers plugged directly into the Raspberry Pi audio output but I fancied eventually building a standalone chess computer so I wanted something that I could build into a case later.

I got the Adafruit TS2012 2.8W Stereo Audio Amplifier and assembled it on the Fuze's included breadboard. Then I added a Breadboard-Friendly 3.5mm Stereo Headphone Jack and a 3" speaker driver.

With the amplifier and speaker setup on my breadboard I connected the Raspberry Pi's analogue audio output to the headphone jack and tested the sound quality. Unfortunately I found the Raspberry Pi's analogue audio output to be pretty poor, with lots of hissing and crackling. Digging around in some Raspberry Pi forums it seemed that this fact was well known to everyone but me.

Most solutions seemed to involve ignoring the Pi's own analogue audio output and using a USB audio device instead. I tried several of these and there was a noticeable improvement in audio quality, however most of them suffered from some annoying loud popping noises, especially at startup. The one that gave me the best results was actually the cheapest that I tried, the Plugable USB Audio Adapter.

  • Ensure that your Rasberry Pi is up-to-date and has the alsa-utils package installed:

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install alsa-utils
  • Edit /etc/modules to add the snd_bcm2835 module if it isn't already there

  • Enable the USB sound card by editing /etc/modprobe.d/alsa-base.conf to comment out the line:

    # options snd-usb-audio index=-2
  • Then reboot:

    sudo reboot

Installing Text-To-Speech Engines on the Raspberry Pi

Install & Test Festival TTS engine:

sudo apt-get install festival
echo "Listen very carefully, I shall say this only once" | festival --tts

Install & Test Espeak TTS engine:

sudo apt-get install espeak
espeak -ven+f3 -k5 -s150 "Listen very carefully, I shall say this only once"

Festival and Espeak are both free, but there is also a commercial TTS engine available for the Raspberry Pi from Cepstral. You can hear this being used in the video. I think it gives a nice natural voice for the human player, but you will have to buy your own copy of the Callie voice from Cepstral, it costs $29.99 and you need to raise a support ticket to buy it as it isn't listed publicly on their website.

Once you have bought your own license for the Cepstral Callie voice, here is how you install & test the Cepstral “Callie” TTS engine:

  • First, extract Cepstral_Callie_arm-linux_6.1.4.tar.gz

  • Then install the Cepstral Callie voice:

    cd Cepstral_Callie_arm-linux_6.1.4
    sudo ./install.sh
  • Ensure alsa-utils alsa-oss packages are installed:

    sudo apt-get install alsa-utils alsa-oss
  • Register the Cepstral Callie voice using your own license key:

    sudo swift --reg-voice --customer-name "YOUR_NAME_HERE" --company-name "" --voice-name Callie --license-key "YOUR_LICENSE_KEY_HERE"
  • Test the Cepstral Callie voice:

    aoss swift -n Callie "Listen very carefully, I shall say this only once"

Configuring Picochess

Once you are running a version of Picochess with my changes you need to tell Picochess that you want to enable the speech output. Picochess uses a config file called /opt/picochess/picochess.ini to allow the user to control its settings.

user-voice = en:Elsie
computer-voice = en:Marvin

You can specify different voices for both the user and the computer players. Voices are specified using the format LANGUAGE:VOICE, where "en" is the only language currently supported and the initial voices are "Marvin", "Elsie" and "Callie" (please note that Callie is a commercial voice that needs to be purchased before use).

I have also added a new config option to allow disabling of the beep for every move, as you probably won't want both the beeps and speech playing at the same time.

What Next?

If there is enough interest from other people wanting speech output from Picochess I will ask the Picochess maintainers about the possibility of merging my changes into the main Picochess releases, so that anyone can try it out.

I will be working on improving the speed of the speech output as it can be quite slow to generate the speech, as well as tuning the pronunciation for each speech engine.

It would be cool if other people could play around with the parameters to the various speech engines and maybe come up with some more voices.

Chess just got noisy!

Read “FUZE Case for Raspberry Pi” next

Facebook, Twitter, Pinterest