Text reader for Ubuntu
I spent ages trying to get Orca to read selected text but there are a mind boggling number of options and while the GNOME (Ubuntu's default desktop manager) documentation is pretty good it never really worked. On further reading there seems to be some issue with Firefox and it was unclear if this had been resolved. I could get the Accessibility Options box to pop up using the short cut keys but none of the key bindings seemed to work for me. It's a shame because Orca comes with all sorts of goodies like reading mnemonics as text, reading camel case words as separate words (very handy if you read a lot of technical documentation!). Anyway, I couldn't get it to work so found another solution; not quite as feature rich but it does exactly what i want.
You need 2 pieces of software installed: something to read selected text (xsel
) and something to read it out (espeak
`) so install both of those:
sudo apt install espeak xsel
To test xsel
is working:
- Open a terminal window.
- Use your mouse to highlight some text in the window.
- Type:
xsel
. Your selected text should be returned by the command.
To test espeak
is working just type:
echo "MrN is Ace" | espeak
and it should read out what is true ;)
This paragraph is from the future! On Ubuntu 22.04, I didn't hear any noise coming from epeak
running in the terminal window on my Ubuntu desktop. This is because you have to specify which audio output device is associated with which application. The easiest way to do this, is to play something long (e.g. cat /etc/services | espeak
) and while it is playing, load in the *Volume Control" application. In the Playback tab (first tab) you will see the Terminal application and its sound meter. Select the audio output device for Terminal and you are good to go. Now back to the past...
Now we just need to put that together. Under GNOME (other Desktop managers may do it differently) we'll create a shortcut key binding to run our command on a magic key combo.
Ubuntu 20
- Open Settings application.
- Go to Devices.
- Go to Keyboard.
- Go down to the bottom and click +.
Ubunti 22
1.Open Settings application.
- Go to Keyboard.
- Go to Keyboard shortcuts
- Click View and Customise Shortcuts.
- Scroll down to Custom Shortcuts and click it.
- Go down to the bottom and click +.
Then:
- Enter a name as "Read selected text".
- Enter command as:
bash -c "xsel | sed -e :a -e '$!N;s/\n/ /;ta'| espeak"
- Click shortcut then make the key combination. I use
CMD+[
on my Mac soWin+[
seemed simple on my PC. - On my Mac the read-text command is a toggle as it's built in. This is not the case when just running a command. I should probably put the read text command into a script so it can detect if it's already running, restart it etc, but that can be a job for another day. For the moment I just need to get up and running, so we'll create something that kills
espeak
. So create another entry by hitting the + button. - Enter a name as "Stop read selected text".
- Enter command as:
bash -c "kill `ps -au | grep '[0-9] espeak$' | awk '{print $2}'`"
- In this case I just picked the bracket next to it as it has the least impact on muscle memory.
That's it, it works in the text editor, browsers and everywhere else. Some browsers use CSS to stop you selecting the text but if you press F7
it'll switch on caret mode which lets you highlight text again. In applications (not web browsers) this is off my default but you should be able to toggle it with F7
too.
1 comment
Comment from: Alina Lapina [Visitor]
Form is loading...
Great stuff! Thank you!
Steps 9-11 didn’t work for me, the setup didn’t make the reading stop. I also modified the reading command to control voice and pitch:
bash -c "xsel | sed -e :a -e '$!N;s/\n/ /;ta'| espeak -v mb-us2 -p 0"