• Tip Jar

Let the Computer Read for You

Text to speech isn’t just for screen readers any more. I find myself writing small speaking applications for my friends and family to use on their computers more and more often. So, I put 2 an 2 together and got 22 and also the idea to share these applications with everyone. The first part is to decide how you would like to trigger the speech. Some of the people I wrote these programs for preferred to access them by right clicking their mouse and selecting the app from a scripts menu. This setup is quite easy, just save the script in the
~/.gnome2/nautilus-scripts/
directory. If you would like them in a menu by themselves, just create a sub folder for them.
mkdir text-to-speech
Other people like to create a keyboard shortcut to launch the script. If you are using Ubuntu Karmic, and I would assume any distro with the latest Gnome, just click on the system menu, preferences, keyboard shortcuts. Click on add, and enter the name of the script in the name field and type the command to launch it in the command field. Usually the command is nearly the same as the name just with a .sh or .py extension. I usually save the scripts in ~/bin so they will be in the execution path. Click apply and the new action is created. You will notice when you scroll down to the bottom of the list that your new action is listed but it says "Disabled". Click on the "Disabled" and press the key combination you would like to use.
Now, for a working example, let’s get the computer to tell us if we have any new tweets waiting. For this script you will need to have twidge and speech-dispatcher installed. First, let’s test for speech-dispatcher. In terminal type:
spd-say "Hello World"
If you hear the words you just told it to say, Hello World, then you are good to go. If you got something that ends with "command not found" then you need to install speech-dispatcher. In ubuntu type:
sudo apt-get install speech-dispatcher python-speechd
When that has finished you will have speech-dispatcher installed. Now it is time to configure it. So, earlier, if you got no speech with the spd-say command but you did get some message about the connection being refused, try the following:
speech-dispatcher
If you see that speech-dispatcher has started then try the spd-say command above. Still no speech, or have just finished installing speech-dispatcher? Type:
spd-conf
Here it is usually OK to just press enter for each question. There are a couple of exceptions though. When it asks for the port it may offer 6561 this needs to be changed to 6560. When it asks for sound driver, unless you have uninstalled pulseaudio, you need to type in pulse and press enter. To get US English, when it asks for the two letter language code enter en-us and press enter. If it doesn’t offer to start speech-dispatcher at startup, add speech-dispatcher to startup programs under system, preferences, startup programs. Click add and enter speech-dispatcher in both fields.
Whew! now that’s done with let’s move on to Twidge. Lots of distros have it packaged. In ubuntu in terminal type:
sudo apt-get install twidge
Then, to configure it, type:
twidge setup
Then, just so Twitter doesn’t get flooded with requests the first time you request all tweets, type:
twidge lsrecent -s
Of course to use Twidge, you will need a Twitter account. Also, this is an excellent opportunity to do a little advertising and shamelessly invite you to follow me on Twitter.
OK, now we have your computer talking and Twidge installed and a shiny new Twitter account, it is at long last time for the script. Open your favorite text editor and paste the following in to it down to and including the line that says end script.
#!/bin/bash
x=0
while [ $x -lt 1 ]; do
newTweets=`twidge lsrecent -u`
if [ ! -z "$newTweets" ] ; then
spd-say -w "You have new tweets waiting."
fi
sleep 300
done
#end script
Save the file. I called it newtweets.sh. This script runs in the background with out interaction, so save it in ~/bin. You may need to create the bin directory. You will need to give it permission to run. In terminal:
chmod 700 ~/bin/newtweets.sh
To get it to run automatically at start up, add it to start up programs. Remember the command includes the .sh extension:
newtweets.sh
Well, I got all of this written before remembering that that script runs in the background and I was supposed to be discussing scripts that launch with a key press or from the context menu. So, let’s add the second part to our Twitter reading scripts. If you want this to be a keyboard shortcut, save the following in ~/bin. If you would rather right click your mouse and start the script from the context menu, save it in the ~/.gnome2/nautilus-scripts/ directory.
In your favorite text editor paste the following down to and including end script:
#!/bin/bash
x=`twidge lsrecent -asu`;for i in $x;do y+=” $i “;done;spd-say -w “$y”
#end script
Save the file as readtweets.sh. Open terminal and change the file’s permissions with one of the following commands depending on where you saved it:
chmod 700 ~/bin/readtweets.sh
chmod 700 ~/.gnome2/nautilus-scripts/readtweets.sh
If you saved it in the nautilus-scripts directory, it is complete. You may need to logout and back in before it shows up in the context menu. If you saved it in the bin directory there is still a little bit left to do. Click on System, Preferences, Keyboard shortcuts. Click add. In the name field enter readtweets. in the command field enter newtweets.sh and click Apply. Scroll down to custom shortcuts. Beside the readtweets shortcut click on the word Disabled. Press the key combination you would like to use to have new tweets read to you. For example:
control+shift+t
That’s it! Now when your computer says you have new tweets waiting, just press control+shift+t to have them read to you. Or, right click and select readtweets.sh from the scripts menu. I hope you have found this useful. Have fun and enjoy.

Using Speech-dispatcher with Yasr

I was wondering if Yasr could use any other synth than emacspeak. Turns out, if you are using Ubuntu intrepid or later, or if you have the latest version of Yasr installed, it can. For those of you who don’t know, yasr is a terminal based screen reader.
Yasr can now use speech-dispatcher. This means, it can use Espeak, or any other synthesizer that speech-dispatcher supports. To get it, in Ubuntu, type:
sudo apt-get install yasr
Once it is installed, you will need to edit the /etc/yasr/yasr..conf file to get the speech-dispatcher support working. First, you need to be sure that speech-dispatcher is installed and working. To get it:
sudo apt-get install speech-dispatcher python-speechd
Once it is installed, type:
spd-conf
to get it set up. You can accept the defaults on all of the questions it asks except the port. For some reason, on my computer at least, it wants to set the port to 6561. It should be 6560, so be sure to type that into the prompt for the port if it says something else. When that has finished, launch it with:
speech-dispatcher
If you want, you can make it start automatically by going to System, Preferences, Sessions and adding speech-dispatcher to the start up programs.
name: speech-dispatcher
command: speech-dispatcher
Now, for the /etc/yasr/yasr.conf file. Open it with sudo, remove the # at the beginning of the speech-dispatcher lines, there are 2 of them. Then add the # in front of the emacspeak lines. Once again, there are 2 of them.
You can change speech rate, pitch, etc by editing the file:
~/.speech-dispatcher/conf/speechd.conf
Most of the lines are commented out, so remember to remove the # if you want your changes to be applied. To launch yasr, type yasr in terminal.

  • Tip Jar