Skip to content

Instantly share code, notes, and snippets.

@John-Appleseed
Last active September 2, 2018 05:40
Show Gist options
  • Save John-Appleseed/e889f3bc31dd4e1643a29dfe6002350f to your computer and use it in GitHub Desktop.
Save John-Appleseed/e889f3bc31dd4e1643a29dfe6002350f to your computer and use it in GitHub Desktop.
Linux Speech Install
# speech.install:
speech.install(){
# requires package libncurses5-dev xsel
# Tested on amd64, arm64
# Issue: festival's `make symlinks` are the full build path to binaries and configs rather than a relative path
# Currently festival/ is extracted out of build_festival/ into $usr_share_dir/ with the voices installed and the festival binaries and configs relinked to $usr_share_dir by a 2nd full recompilation. make clean && ./configure && make
# Either change github.com/festvox/festival symlinks to relative or revise setup_festival_mbrola.sh to install voices to target path
# TODO quickfix: setup_festival_mbrola.sh festival-mbrola-voices should have working directory ($work_dir) and target directory ($target_dir) for the voices to be installed in the target $usr_share_dir/festival folder.
LAB="${LAB-:"$HOME/Lab"}"
mkdir -p "$LAB/speechtools"
cd "$LAB/speechtools"
work_dir="."
usr_share_dir="/usr/local/share"
#usr_share_dir="/usr/share"
echo "Building festival and speech_tools"
curl -O https://raw.githubusercontent.com/John-Appleseed/setup-festival-mbrola/master/setup_festival_mbrola.sh
#bash setup_festival_mbrola.sh "$usr_share_dir" festival # TODO: Install in destination
bash setup_festival_mbrola.sh "$work_dir" festival
bash setup_festival_mbrola.sh "$work_dir" mbrola
# Download, Setup, and Move the voices into festival
bash setup_festival_mbrola.sh "$work_dir" festival-mbrola-voices
echo "Installing festival and speech_tools to $usr_share_dir/"
sudo mv "$work_dir/build_festival/speech_tools" "$usr_share_dir/" # speech_tools not needed for festival runtime. Need for festival recompile
# Move festival to its destination
sudo mv "$work_dir/build_festival/festival" "$usr_share_dir/"
echo "Installing mbrola to /usr/bin"
sudo mv "$work_dir/build_mbrola/mbrola" /usr/bin/
# TODO: reduce the extra recompile by editing setup_festival_mbrola.sh to install voices to target festival without the setup files
cd "$usr_share_dir/festival"
make clean && ./configure && make
echo "Recompiled: festival binary relinked correctly to $usr_share_dir/festival"
#./configure && make && make make_library
echo "Add $usr_share_dir/festival/bin to \$PATH"
echo "export PATH="$usr_share_dir/festival/bin:\$PATH""
export PATH="$usr_share_dir/festival/bin:$PATH"
#export PATH="`pwd`/$work_dir/build_mbrola:$PATH"
echo "Linking $usr_share_dir/festival/bin/festival to /usr/local/bin/"
sudo ln -s $usr_share_dir/festival/bin/festival /usr/local/bin/
echo -e "\n\n"
echo "Hello World! Mic Check"
echo "Hello world! This is the festival kal_diphone American English voice. Open the pod bay doors, dave" | padsp festival --tts --pipe
echo ""
echo "Change default voice: edit $usr_share_dir/festival/lib/voices.scm"
echo "Recommended voices: en1_mbrola, rab_diphone, don_diphone, us2_mbrola"
echo "Change voice speed: edit $usr_share_dir/festival/lib/voices/english/kal_diphone/festvox/kal_diphone.scm"
echo "Set voice speed: Duration_Stretch 0.65"
}
# ---
#!/bin/bash
# padsp festival to use the pulseaudio soundserver
# aoss festival to use the alsa soundserver
# Speak selected text
xsel | padsp festival --tts
@John-Appleseed
Copy link
Author

John-Appleseed commented Mar 21, 2018

speech.install:

One stop command to install Text To Speech for Linux on amd64 and arm64 (46 minutes to install on RPI2).

speech.install installs the festival command with a simple set of english and american voices.

Distro festival is currently broken on both apt-get and emerge

  • apt-get has festival 2.4 but will occasionally fail with "pipe_open: fork failed"
  • emerge has festival 2.1 which instantly bricks itself with a "Segmentation fault (core dumped)" (without a core dump...)
  • voices are not installed by default in both package distros

Recently, Dec 25, 2017, festival 2.5 was release with support for GCC 6.2.0 along with a fix for the threading issue, and invalid memory access seg faults, thank you Devs!

Install

To get started, download gist, source speech_install.sh, and run speech.install to get the festival 2.5 goodness

https://gist.github.com/John-Appleseed/e889f3bc31dd4e1643a29dfe6002350f

Activate Text To Speech by echoing text via pipe or by reading txt files with the command festival --tts

echo "Hello World. Festival is alive and well" | padsp festival --tts
festival --tts hello_world.txt

Text To Speech

To complete the festival TTS experience install tts.sh to enable text selection speech via keyboard shortcut

  • Copy and execute the tts.install code block below into your shell
sudo tee "/usr/local/bin/tts.sh" > /dev/null <<'EOF'
#!/bin/bash
# /usr/local/bin/tts.sh

# padsp festival to use the pulseaudio soundserver
# aoss festival  to use the alsa soundserver 

# Speak selected text
xsel | padsp festival --tts

EOF

sudo chmod +x /usr/local/bin/tts.sh
  • Setup the TTS keyboard shortcut as super + esc to /usr/local/bin/tts.sh

  • MacOS has the TTS (Text To Speech) command as option + esc. For Linux, option + esc is for window switching, so control or super + esc works for Text To Speech

  • With MATE, Menubar > System > Preference > Hardware > Keyboard Shortcuts > + Add new

  • With Gnome, Activity Menu > Settings > Keyboard > + Add new

Now that you have Text To Speech selection installed, select your text on any webpage or pdf, press super + esc and enjoy the reading festival!


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment