espeak works fine but voice is creepy (especially in french !). This post explains how to use the google voice api to get a wonderful female clear voice.

first, create speech.sh. It contains a function “say()” which call translate.google.com with parameter $* (parameter of your shell)

#!/bin/bash
say() { local IFS=+;/usr/bin/mplayer -ao alsa -really-quiet -noconsolecontrols “http://translate.google.com/translate_tts?hl=en&sl=en&tl=fr&ie=UTF-8&oe=UTF-8&multires=1&otf=1&ssel=3&tsel=3&sc=1&text=$*” 2>/dev/null;}
say $*

Notice that this url will speak french. If you want to speak english, just change “tl=fr” by “tl=en” (german: tl=de, spanish: tl=es, etc.)

Change attribute of your sh file to allow execution and try it. Notice that this URL only accepts sentence less than 100 letters.

chmod u+x ./speech.sh
./speech.sh “Bonjour. Je veux manger du fromage.”

Now, you can use it in your C file.

void speak(char *sLine)
{
    char sCmd[255];
    sprintf(sCmd,”./speech.sh %s”,sLine);

    // if (TRACE) printf(“[i] say : %s”,sLine);
    system(sCmd);

}

To read a whole text (length > 100 letters)

char sToBeRead[100];
f = fopen(fileName,”r”);
if (f != NULL)
{
    // read all text
     while (!feof(f))
     {
        if (fgets(sToBeRead, 100, f)!=NULL)
        {
           speak(sToBeRead);
        }
     }
    fclose(f);
   return 1;
  }
return 0;
}

At this end of this post, your wife/girlfriend should not like the new voice of your magic mirror… 😉

c3PO