- Get an SSD cloud server in less than a minute!
- Protect your important files with Dropbox. Get your free account today!
- Get paid for reading email!
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
directory. If you would like them in a menu by themselves, just create a sub folder for them.
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:
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:
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:
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.
while [ $x -lt 1 ]; do
newTweets=`twidge lsrecent -u`
if [ ! -z "$newTweets" ] ; then
spd-say -w "You have new tweets waiting."
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:
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:
x=`twidge lsrecent -asu`;for i in $x;do y+=” $i “;done;spd-say -w “$y”
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:
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.