OK try this on for size! It's my hatchet job to get the functionality I used to get from my Mac where a key combination would speak any text that was highlighted on screen.
First of you need the small command line utility xsel and unicode converter uni2ascii and command line browser Lynx:
Code:
sudo apt-get install xsel uni2ascii lynx
Then copy this script to your computer and save it as speak
speak
Code:
#!/bin/bash
# Read highlighted text on screen
# convert text into usable ascii text (if anyone has a better way of
# doing this which produces text which can be read by festival please let me know)
ascii()
{
echo "<html><body>" > /tmp/convert.htm
cat | uni2ascii -a Q -a D 2> /dev/null >> /tmp/convert.htm
echo "</html></body>" >> /tmp/convert.htm
cat /tmp/convert.htm | lynx -stdin -dump
rm /tmp/convert.htm
}
#Stop running instance if found then exit
pidfile=/tmp/speak.pid
if [ -e $pidfile ]; then
pid=`cat $pidfile`
if kill -0 $pid 2> /dev/null; then
echo "Already running...Killing process"
# Ramble on kill
# kill $pid 2> /dev/null
# Stop at end of sentence kill
for i in `ps -ef| awk '$3 == '${pid}' { print $2 }'`; do
kill $i
done
exit 0
else
rm $pidfile
fi
fi
# Otherwise speak selected text
xsel -o | ascii | festival --tts 2> /dev/null & pid=$!
echo $pid > $pidfile
wait $pid 2> /dev/null
rm $pidfile
Save the file speak then make it executable and copy it to the path.
Code:
chmod +x speak
sudo mv speak /usr/local/bin/
You can test it from the terminal now by running speak. Then setup a keyboard shortcut key to run speak.
If you're running Ubuntu without visual effects (no compiz) run gconf-editor and open /apps/metacity/global_keybindings and set the first available run_command, normally run_command_1 to your shortcut. I use <Super>F2. Now set the command under /apps/metacity/keybinding_commands and which ever command number you used (i.e. command_1) and put in the command /usr/local/bin/speak.
If you're running Ubuntu with visual effects (compiz) run ccsm (you may have to install it first). Then under General>Commands set command line 0 (or the 1st available) to /usr/local/bin/speak and then set your keybinding (I use <Super>F2).
The quick kill that I've defaulted to I think leaves some files lying around in the /tmp directory but I don't think this is too much of a problem as they'll just be wiped the next time you restart and wont take up much space. The other way allows festival to close down its speech process and it just keeps wittering on until it can be arsed to close it down.
Bookmarks