How to text-to-speech output using command-line?

Solution 1:

In order of descending popularity:

  • say converts text to audible speech using the GNUstep speech engine.

    sudo apt-get install gnustep-gui-runtime
    say "hello"
    
  • festival General multi-lingual speech synthesis system.

    sudo apt-get install festival
    echo "hello" | festival --tts
    
  • spd-say sends text-to-speech output request to speech-dispatcher

    sudo apt-get install speech-dispatcher
    spd-say "hello"
    
  • espeak is a multi-lingual software speech synthesizer.

    sudo apt-get install espeak
    espeak "hello"
    

Solution 2:

espeak is a nice little tool.

I just like playing around with it in a command line. You might find it conflicts with Pulseaudio so I'm using a long-winded version that negates having to set it up properly.

sudo apt-get install espeak
espeak --stdout "this is a test" | paplay

espeak --help will show you the options to calibrate reading speed, pitch, voice, etc.

When you're doing your notes, save them as a text file and then:

echo "these are my notes" > text.txt
espeak --stdout -f text.txt > text.wav
paplay text.wav # you should hear "these are my notes"

You can then play around with ffmeg et al to compress this down from PCM to something more manageable like MP3 or OGG. But that's a different story.

Solution 3:

From man spd-say:

NAME
       spd-say - send text-to-speech output request to speech-dispatcher

SYNOPSIS
       spd-say [options] "some text"

DESCRIPTION
       spd-say  sends text-to-speech output request to speech-dispatcher process which handles it and ideally outputs the result
       to the audio system.

OPTIONS
       -r, --rate
              Set the rate of the speech (between -100 and +100, default: 0)

       -p, --pitch
              Set the pitch of the speech (between -100 and +100, default: 0)

       -i, --volume
              Set the volume (intensity) of the speech (between -100 and +100, default: 0)

Hence you can get text-to-speech by following command:

spd-say "<type text>"

Ex:

spd-say "Welcome to Ubuntu Linux"

You can also set speech rate, pitch, volume etc. see man-page.