84

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

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

13 Answers 13

125

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"
    
  • 13
    spd-say appears to be pre-installed in 14.04 and later: releases.ubuntu.com/trusty/… – Ciro Santilli 新疆改造中心法轮功六四事件 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 – phil294 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
18

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.

  • 1
    very nice, one can also try the Graphic User Interface to espeak, espeak-gui. – Sabacon Jan 16 '11 at 13:15
14

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
6

Mbrola doesn't work since 11.10.

SVOX (pico) tools are easy to install, easy to use and brings good quality voices in Ubuntu. Install it:

sudo apt-get install libttspico0 libttspico-utils libttspico-data

Even more easy, you can use LibreOffice in combination with SVOX (pico) tools by install the "Read Text" extension and you obtain a "GUI" for this excellent TTS software:

Set up Read Text Extension's options with Tools - Add-ons - Read selection.... Use /usr/bin/python as the external program. Select a command line option that includes the token (PICO_READ_TEXT_PY).

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

And yet another espeak gui: gespeaker. It uses both espeak and mbrola engines. Also, it has more options than espeak-gui.

3

The following is not a FLOSS solution, but you may find it worthwhile. (it is a wine solution),

I'm personally very keen on TTS, I use it quite often... eg. listening to a rambling discourse which I would never bother to stick with otherise (because I need to get another cup of coffee... :)

A few things I've discovered along the way.. or should I say, things I haven't discovered along the way... To put it bluntly: Every piece of FOSS TTS voice software I've tried is under par and therefore unsuitable for any semi-protracted listening...

I currently use ATnT's NaturalVoices. It is only available for Windows (maybe the Mac), but it does run under wine in Ubuntu .. (it has minor glytch, where I sometimes need to click on the panel when I move away from the reader... It is a minor issue when compared to the advantage gained by quality of speech from NatualVoices.

Some other things I've found to be virtually essential for a half-sensible listening experience, are;...

  1. These TTS progamas are not intelligent (well maybe as intelligent as a young baboon) .. so they need every bit of help they can get. and there is one (and only one Reader program I've found which helps greatly in this.. The app is called ReadPlease (2003 Pro)... It allowd you to specially modify words and groups of word to be pronounced as you want them... It is by no means perfect, but for me, it made the difference between the entire process being usable and not usable...

  2. The speech in Natural Voices is "okay", but it is a bit boring. There are other good products too, but they are all for Windows, unfortunately)..
    It infeclts surprisingl well sometimes .. but OMG, initially it is a pain! .. so #2 is *patience... and lots of updating of your "special words" list ... By patience, I mean you(I) actually became accustomed to my particular baboon's speech patterns :)... and by the way, I currently have about 3000 words that now sound "Human" enough that I no longer cringe when I hear them.

    3.. "Follow the Bouncing Ball" ... Again because the voice is never as good as a real speaker, things sometimes need to be clarified .. . The Reader program I use has one feature for which I even put up with its clunky looking interface.... Is has a "select the currently being read" word option.. Many readers have this, but ReadPlease keeps the current line bang on center of the screen .. This is invaluable to be able to see ahead and behind to quickly re-read what you just missed (so auto-centering the curent line is good)...

Well that's my experience.. I'm going to make a coffee now, and while I'm doing it, I'll be listening to this, to see how it "reads".... TTS is surprisingl good for picking up typos (I make lots of typos)...

If something as good as ATnT NaturalVoices turns up on the Ubuntu repository, I'll jump at it.

Here is a link to some samples of Natural Voices: I use "MIke"

3

SVOX pico2wave

that s what I use. And it sounds natural, it s easy to understand, it recognise Units (m, °C,kg, ...)

Here is my first post to pico2wave

Natural Sounding Text to Speech?

All you have todo is:

Go to Ubuntu Software Center and search for "pico". You ll find 4 or 5 entries with "Small Footprint Ling...". Install them.

A possible use of pico2wave is described in my first posting (follow the link above).

Bye

  • i have used your way can you pls tell me how to get a naturl sweet female voice using your way – user49557 Jun 19 '15 at 13:03
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

Even though you've already accepted an answer, I wanted to mention festival, which I like quite a lot too. This post on the Ubuntu forums has a lot of information on getting very nice voices set up for it.

2

Meet espeak-ng - A multi-lingual software speech synthesizer:

espeak-ng "text to read"
espeak-ng -f "~/file to read"

It uses a default English voice, but there are numerous other voices for other languages and even dialects available and can be listed with espeak-ng --voices (for all) or e.g. espeak-ng --voices=en (for English). They can be set with -v together with either the language abbreviation or the file name, e.g. for Scottish or Swahili:

espeak-ng -v en-gb-scotland "text to read" # language name
espeak-ng -v bnt/sw "text to read" # file name: “bnt” for Bantu, “sw” for Swahili

There are many other options available, e.g. -s for the speed and -w to write the output to a wave file, see the manpage linked below.

Further reading

espeak-ng (“ng” for “next generation”) is an actively developed fork of the original espeak speech synthesizer software, see the History chapter on Wikipedia. Both are available from the official sources via the package espeak or espeak-ng respectively.

0

Balabolka under Wine works fine (for me) with SAPI4 voices (SAPI5 voices are not detected on my Linux system). It can open files and start reading.

Here is link to wine's AppDB entry for Balabolka: https://appdb.winehq.org/objectManager.php?sClass=application&iId=17859

0

The tool gTTS is great for generating audio files from text. It uses the Google Translate's text-to-speech API, and generates mp3 files.
Given that it uses pip for installation, I strongly recommend you install Miniconda, and then use conda to create an environment where you can install gTTS. You can download Miniconda from here:

https://docs.conda.io/en/latest/miniconda.html

The GitHub repository for gTTS is:

https://github.com/pndurette/gTTS

And you can find the documentation of gTTS here:

https://gtts.readthedocs.io/en/latest/

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.