Thursday, February 26, 2015

Installing Pico TTS

Sooner or later you may wish to hear your Raspberry Pi speaking.

It's nice to get messages from your RPi by Whatsapp, or reading on a small display (or TV), but hearing this device answering you with a real voice could be amazing!

There are several TTS (Text To Speech) engines avaliable for a Raspberry Pi and you can find a list here.

Usually offline engines suffer from low quality voices (and sometimes limited languages avaliable). On the opposite side, online TTS engines could have really high speech quality, but you need an internet connection (and your recorded voice will be analyzed from someone else).

Fortunately there is a really good engine available for our device that produces quite good voices, but is completely offline: SVOX Pico.

The bad thing is that it's not easy to install. On many websites you can find an "easy" installation using just aptitude (apt-get install libttspico), but if you try it, you will find that this doesn't work, even adding the non-free repository for installation.

Anyway the sources are available, so you can compile the packages by yourself. I found just a bunch of information about this topic online, so I'm going to summarize all the steps in this post.

First of all you need to open the file /etc/apt/sources.list and check it contains (uncommented) the following lines:

deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
deb-src http://mirror.ox.ac.uk/sites/archive.raspbian.org/archive/raspbian/ wheezy main contrib non-free rpi

If these are not present or they are commented, edit and save the file.
Then launch an update:

sudo apt-get update

Next you need to install some dependecies for the compilation:

sudo apt-get install fakeroot debhelper automake autoconf libtool help2man libpopt-dev hardening-wrapper

Probably fakeroot is already installed, but I put it anyway just in case you are missing it. Now we can create the folder to keep the sources and download them:

mkdir pico_build
cd pico_build
apt-get source libttspico-utils

After downloading the sources, you should find a folder named like svox-1.0+git20110131 that will contain all the files. Note that the last part could be different, so please check before proceeding.

Enter the sources folder and prepare the packages:

cd svox-1.0+git20110131
dpkg-buildpackage -rfakeroot -us -uc

Now go for a coffee... Compiling the packages require about 15-20 minutes to complete, but fortunately it's an autonomous task, so there's no need for you to stay beside the RPi.
If no errors arose during packages compilation, you should find four packages in the pico_build folder. Check by changing folder and listing files:

cd ..
ls

These are the packages in my folder:

libttspico0_1.0+git20110131-2_armhf.deb
libttspico-data_1.0+git20110131-2_all.deb
libttspico-dev_1.0+git20110131-2_armhf.deb
libttspico-utils_1.0+git20110131-2_armhf.deb

To use the library you just need three of them, but they have to be installed in a specific order, so type:

sudo dpkg -i libttspico-data_1.0+git20110131-2_all.deb
sudo dpkg -i libttspico0_1.0+git20110131-2_armhf.deb
sudo dpkg -i libttspico-utils_1.0+git20110131-2_armhf.deb

Now Pico engine is ready to be used. Connect audio output and test the library typing:

pico2wave -w test.wav "it works! "
aplay test.wav

You can change language with option -l and you can choose english (uk or us), german, italian, french or spanish (inside the sources folder you can also find some documentation).

Now that you have built the packages, save them somewhere, so next time you need to install SVOX Pico engine you can just install them and avoid the whole compilation process.

In my next post i will show you how to integrate SVOX Pico TTS engine with our Yowsup parser and how to make the voice just a bit more interesting...

36 comments:

  1. I get and error: -bash: !": event not found

    occurs when testing using the command

    pico2wave -w test.wav "it works!"

    ReplyDelete
    Replies
    1. This is a linux bash "feature" and it's easy to solve. You can remove the exclamation mark from the sentence or put a space between the exclamation mark and the quotes: pico2wave -w test.wav "it works! ". This is also valid for other special linux characters.
      I changed the post above this way for everyone.

      Delete
  2. Does your installation actually play other languages? I was unable to use French with either the -l or --lang argument of pico2wav. I tried many combinations, like "fr", "FR" or "fr-FR".

    ReplyDelete
    Replies
    1. I have no problems with other languages. For french should work with:

      pico2wave -l fr-FR -w test.wav "bonjour"

      This works perfectly for me...

      Delete
  3. I was able to follow along with no errors up until trying to play the WAV file. After "aplay test.wav" I get "aplay: playback:2483: read error"

    Thoughts?

    ReplyDelete
    Replies
    1. Ok, I ran both as root, and it worked. But I don't think that's the "right answer". Any advice?

      Delete
    2. I can play Pico generated files without any problem (and you are right when you say that it should work without sudo).
      Try to upload a simple wave file to your RPi and play it (without sudo), just to see if there is still an error...

      Delete
  4. Playing a file works without a problem. Do I need to add write permissions to the folder where the wav is created?

    ReplyDelete
    Replies
    1. Write permission should not be a problem, if the file is created. Anyway it could be an access issue, so you can try to put standard flags with the command chmod typing this (you should be outside the folder):

      sudo chmod 755 foldername

      where foldername is the name of the folder where you have the generated wave file.

      Another thing you can do is doing both update and upgrade to be sure that you have all the latest libraries (of course if you do not have already done this).

      Delete
  5. How to install portuguese voice to RPi Svox pico tts?

    ReplyDelete
    Replies
    1. Sorry, but pico tts (at least on debian systems) can use just german, english, french, italian and spanish. Maybe you could try to look at the sources of the software to see if there's a way to add new voices, but I think it would not be an easy task...

      Delete
  6. Have you tried installing SVOX Pico onto Raspbian Jessie? I'm having the toughest time on it.

    ReplyDelete
    Replies
    1. I tried Jessie, but I found so many problems when installing many of the softwares I use (most of them are standard debian packages) that I reverted to Wheezy.
      I did not try with Pico, but it's not a surprise that there are problems in installing it on Jessie... Maybe it's stil too early to use this new Debian distro with RPi.

      Delete
    2. Stefanus Kurniawan03 December, 2015 04:15

      https://packages.debian.org/jessie/all/libttspico-data/download
      https://packages.debian.org/jessie/armhf/libttspico0/download
      https://packages.debian.org/jessie/armhf/libttspico-utils/download

      Try to install them all in order

      Delete
  7. dpkg-buildpackage: source package svox
    dpkg-buildpackage: source version 1.0+git20110131-2
    dpkg-buildpackage: source distribution unstable
    dpkg-buildpackage: source changed by Samuel Thibault
    dpkg-buildpackage: host architecture armhf
    dpkg-source --before-build svox-1.0+git20110131
    fakeroot debian/rules clean
    dh clean --sourcedirectory=pico
    dh_testdir -O--sourcedirectory=pico
    debian/rules override_dh_auto_clean
    make[1]: Entering directory '/home/pi/pico_build/svox-1.0+git20110131'
    rm pico/pico2wave.1 ||:
    rm: cannot remove ‘pico/pico2wave.1’: No such file or directory
    cd pico && test -f Makefile && make clean ||:
    chmod +x ./pico/autogen.sh
    cd pico && ./autogen.sh clean
    make[1]: Leaving directory '/home/pi/pico_build/svox-1.0+git20110131'
    dh_clean -O--sourcedirectory=pico
    dpkg-source -b svox-1.0+git20110131
    dpkg-source: info: using source format `3.0 (quilt)'
    dpkg-source: info: building svox using existing ./svox_1.0+git20110131.orig.tar.gz
    dpkg-source: error: cannot represent change to pico/INSTALL:
    dpkg-source: error: new version is symlink to /usr/share/automake-1.14/INSTALL
    dpkg-source: error: old version is nonexistent
    dpkg-source: error: cannot represent change to pico/COPYING:
    dpkg-source: error: new version is symlink to /usr/share/automake-1.14/COPYING
    dpkg-source: error: old version is nonexistent
    dpkg-source: error: unrepresentable changes to source
    dpkg-buildpackage: error: dpkg-source -b svox-1.0+git20110131 gave error exit status 2


    Any idea?

    ReplyDelete
    Replies
    1. Are you using Debian Jessie? I found several similar issues like this one when I used it. Probably if this is also your case it's a Jessie problem. I did not dig these errors as for me Wheezy is more than enough.
      Anyway in Jessie you could try to install the packages suggested by Stefanus Kurniawan in the comment just above without the need to compile them...

      Delete
    2. Yes, I'm using Debian Jessie. Thanks, I'll try.

      Delete
  8. If you are using Jessie as me, you can try to install libttspico0 (sudo apt-get install libttspico0) and then libttspico-utils (sudo apt-get install libttspico-utils) (package libttspico-data is a dependency of libttspico0).
    That works fine for me

    ReplyDelete
    Replies
    1. Thanks so much for posting this. I made it through most of the tutorial and then encountered that "error exit status 2" result. Your solution worked for me on Jessie (recently installed). My pi is talking to me!

      Delete
    2. Holy crap, that actually worked. No compiling necessary, just the two commands and then you're up and running on Raspbian Jessie!

      Thanks a billion!

      Delete
  9. I had to add
    apt-get install automake1.11
    Without it my dpkg-buildpackage -rfakeroot -us -uc was not working.

    ReplyDelete
  10. Is it possible to run the pico tts from a python file, where it has to run on a text file? rather than running it on the command line?

    ReplyDelete
    Replies
    1. Actually I'm using it from Python, but with just os calls like the following:

      os.system("pico2wave -l it-IT -w voice.wav \""+mytext+"\"")
      os.system("play -v 0.2 voice.wav tempo -s 0.9")

      First line creates the audio file and the second just plays it. Please note that for playing I'm using SOX (so I can change some audio parameter), but you can of course use whatever method you wish to play the audio file.

      Pico tts do have an API interface (you can find docs in the sources folder), but you need to create a python wrapper for the C headers. I never did this as for my needs the os calls are just enough.

      Delete
  11. Carlos, I have a question... how i create a python wrapper for the C headers?.

    ReplyDelete
    Replies
    1. I never went into wrappers programming, so I really can't help you on this. Anyway you should find several sources on this topic by making a search on google.
      For my needs it's far easier calling it by the os.system function...

      Delete
    2. Can u explain me, how do it?
      i wanna put it into script from python...

      Delete
    3. You can donwload the following script:

      http://www.mascal.it/public/speak.py

      This just gets a text from the command line and it speaks it using Pico and Sox. You can easily modify to be used inside a Python function and pass the sentences as a parameter.

      Delete
  12. While installing "hardening-wrapper" package, I got this error:

    Error:Package hardening-wrapper is not available, but is referred to by another package.This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package 'hardening-wrapper' has no installation candidate

    ReplyDelete
    Replies
    1. If you are on Debian Jessie, you can try with

      sudo apt-get install libttspico0 libttspico-utils

      to install the library.
      I did this way just few days ago without any issue.

      Delete
  13. well written. I was able to setup PICO tts in minutes following your steps. Thanks a ton mate !!!

    ReplyDelete
  14. Thanks.. set it up, works fine..great post

    ReplyDelete
  15. Thank you for this tutorial! It has helped me install pico2wave on the latest 32bit raspbian os; just had to use more sudo than you did; for dpkg-buildpackage and from then on ; not using sudo there didn't work for me. also had to install some packages,

    Thanks!

    ReplyDelete

Note: Only a member of this blog may post a comment.