73

How to get speech output from entered text by using command-line?

Also facility to change speech rate, pitch, volume etc using simple command.

116

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"
    
  • 11
    spd-say appears to be pre-installed in 14.04 and later: releases.ubuntu.com/trusty/… – Ciro Santilli 新疆改造中心996ICU六四事件 Jul 28 '16 at 11:52
  • 3
    Also sudo pip install gTTS, (Google Text to Speech/github.com/pndurette/gTTS) then gtts-cli "hello" -o hello.mp3 you can pipe it to mpg123 - as well. gtts-cli "why, hello there" | mpg123 -. – Elijah Lynn Apr 6 '17 at 17:31
  • unfortunately, spd-say does not seem to be able to play tts simultaneously, only one a time – Blauhirn Jul 7 '17 at 15:51
  • @ElijahLynn doesn't work – Dims Jan 19 '18 at 12:49
  • espeak/spd-say is the best for memes (the others can't even pronounce the word "meme" correctly). Best I can tell spd-say uses espeak as its backend (the voices sound the same). – QwertyChouskie Aug 11 '18 at 23:16
13

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.

  • 3
    spd-say -t female2 "text" makes it bearable – scorpiodawg Jun 5 '18 at 17:59
4

Python Google Speach :

pip install google_speech

google_speech "Test the hello world"

Svox From Android :

apt-get install svox-pico

pico2wave --wave=test.wav "Test the hello world"
play test.wav

Svox Nanotts :

git clone https://github.com/gmn/nanotts.git
cd nanotts
make

./nanotts -v en-US "Test the hello world"

Links - Wiki :

Comparison of speech synthesizers

  • 1
    To install and use google_speech on ubuntu 18.04 I had to install python3-pip and libsox-fmt-mp3 and use pip3 install google_speech. – artm Jul 1 '18 at 9:14
3

For festival (the voice seems more natural to me):

sudo apt-get install festival

echo "hello" | festival --tts

Pitch and speed configuration:

create ~/.festivalrc:

(Parameter.set 'Audio_Command "play -b 16 -c 1 -e signed-integer -r $SR -t raw $FILE tempo 1.5 pitch -100") (Parameter.set 'Audio_Method 'Audio_Command)

See also http://www.solomonson.com/content/ubuntu-linux-text-speech

Update: tried on another ubuntu computer. Had to install english speech engine package to work with festival properly:

sudo apt-get install festvox-kallpc16k

Also play is a cli command which comes with sox package:

sudo apt-get install sox

2

November 2017 Ubuntu 16.04

For my project, cron jobs that can talk, espeak is the simplest.

sudo apt-get update
sudo apt-get install espeak

For the first part, making the system speak the time requires a single cron entry

0 * * * * /home/username/scripts/saytime

saytime:

#!/bin/bash
echo "\`$(date +%H)\` Hundred" | espeak

It can receive input via stdio, like so:

cat textfile | espeak -s 100

For reference, here are selected command-line options for eSpeak:

espeak [options] [""]

-a

 Amplitude, 0 to 200, default is 100

-g

 Word gap. Pause between words, units of 10mS at the default speed

-k

 Indicate capital letters with: 1=sound, 2=the word "capitals",

 higher values indicate a pitch increase (try -k20).

-l

 Line length. If not zero (which is the default), consider

 lines less than this length as end-of-clause

-p

 Pitch adjustment, 0 to 99, default is 50

-s

 Speed in words per minute, 80 to 450, default is 175

-v

 Use voice file of this name from espeak-data/voices

-w

 Write speech to this WAV file, rather than speaking it directly

-z

   No final sentence pause at the end of the text

--voices=

 List the available voices for the specified language.

 If <language> is omitted, then list all voices.
  • 1
    This tool is already mentioned. All you seem to add is copy pasting the manpage here. – Olorin Nov 20 '17 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.