- Download tts.py to your Desktop.
- Install dependencies:
sudo apt install espeak python3-pyqt6 - Make runnable:
cd ~/Desktop; chmod +x ./tts.py - Create
tts.desktop
#!/usr/bin/env xdg-open
[Desktop Entry]
Name=Text To Speech (espeak)
Exec=/usr/bin/python3 /home/$USER/Desktop/tts.py
Icon=audio-on
Terminal=false
Type=Application
Categories=Utility;Short and sweet single Python script. Built in Qt 6. Supports both Wayland and X11
Below is deprecated because Wayland has no support for retrieving selected text.
For speed reading, researching, programming, editing and writing.
Tested on Ubuntu 24.04, 22.04, 22.10, 23.04, 23.10, but should work on similar distributions such as Mint, Debian, Pop OS. xsel required so espeak can read from clipboard. Works with espeak or espeak-ng.
sudo apt install espeak xsel -y- Set your custom shortcuts. See Gnome or KDE below.
- With your mouse, select text you want read aloud, press your Read keys.
- System Settings β‘ Keyboard β‘ Keyboard Shortcuts β‘ Custom Shortcuts β‘ +
- Read
bash -c "espeak -s260 -g0 -p40 -v english-us \"$(xsel | sed -e :a -e 'N;s/\n/ /;ta')\"" - Stop Reading
bash -c "killall espeak" - Recommended keys SUPER + R (Read) and SHIFT + SUPER + R (Stop Reading)
- With your mouse, select text you want read aloud, press your Read keys.
KDE is a little different because custom shortcuts have an issue with multiple commands in the same action, but this works:
- System Settings β‘ Shortcuts β‘ Custom Shortcuts β‘ Edit .. New .. Global .. Command
- Read
xsel > /tmp/speak.txt | espeak -s260 -g0 -p40 -v english-us -f /tmp/speak.txt - Stop Reading
killall espeak - Recommended keys SUPER + R (Read) and SHIFT + SUPER + R (Stop Reading)
- With your mouse, select text you want read aloud, press your Read keys.
-s260Speed of reading (260 is faster).-g0Delay between words (0 is no delay).-p40Pitch (50 is normal).-v english-usVoice pack (en-us forespeak-ng).
The sed is required to replace newlines properly. Reference: https://linux.die.net/man/1/sed
-e :aSetsalabel for looping.NRead next line into substitute buffer ... or$!N($go to EOL,!Nexit if no more newlines to read);s/\n/ /Substitute newlines with space.;taLoop to labela.
Some distributions come with espeak-ng which can be used with only minor changes.
- Read
bash -c "espeak-ng -s260 -g0 -p40 -v en-us \"$(xsel | sed -e :a -e 'N;s/\n/ /;ta')\"" - Stop Reading
bash -c "killall espeak-ng"
ps -ef | grep "espeak" | tr -s ' ' | cut -d ' ' -f2 | xargs kill -9
Because my favorite TTS reader gespeaker (python frontend to espeak) is unmaintained, and most other options suck or are browser only.


