A Liux commandline voice synthesis utility to speak text aloud.
"it sounds like the speech synthesis from the WarGames film"
—overheard during a demonstration
"Oh, it's 'text-to-speech' in Linux", you might say. Well, yes, but it's not great. Released in July 2007, it can be used to echo direct input as in espeak "the only winning move is not to play"¹ and of course, it can read the result of a command piped into it as in. Great it is not; the voices are clearly relatively crudely computer-generated and it does sound rather mechanical and somewhat dated. Various voices are available; I use it with the argument -v en-rp which approximates a British received pronunciation accent. the output may be crude, but for simple applications, it may just be sufficient.
The different voices can be listed with espeak --voices. It's been quite amusing to use with such voices as ancient greek or West Indian on occasion.
Usage
Simple use includes reading a text file: espeak -f {filename}. Other arguments include:
-a [0-20] Varies the amplitude
-p [0-99] varies the pitch
-s varies the speed in words per minute (defaults to 160)
-w outputs to a named .WAV file
--punct speaks the names of punctuation marks
Example in a moderately useful Bash script
This script came about after a conversation with Estelore which sprang from my reading their Random Number Generation for the Visually Impaired. It's a demonstration script and I'm not sure how valuable it would be given the limits of espeak, but it works and if you listen carefully you can indeed hear the values being spoken out. The arguments are the number of dice and the number of faces per die. To use, save the file and call it using (for example`) dice-say 3 20. The script should work under Windows subsystem for linux or in a MacOS terminal.
#!/bin/bash
# Function to roll a single die with a given number of sides
roll_die() {
local sides=$1
espeak -v en-north $((RANDOM % sides + 1))
}
# Check if correct number of arguments is passed
if "$#" -ne 2 ; then
echo "Usage: $0 "
exit 1
fi
# Get the number of dice and sides per die
num_dice=$1
sides_per_die=$2
# Roll the dice
for (( i=1; i<=num_dice; i++ ))
do
roll=$(roll_die $sides_per_die)
espeak "Die $i rolled: $roll"
done
the scene from WarGames
$ xclip -o | wc -w
373