Blog Posts Programming Python

Python – Making Use of Google’s Text To Speech Translation Tool

Text to speech (tts) is a difficult task to get right and there are quite a few packages that show just how hard with their terrible tinny voices, these are also usually only limited to English, which for the larger part than most people would like to believe don’t find it very useful. Nevermind, Google to the rescue, their Translation tool has had the ability to also voice translations for a while now. So wouldn’t it be awesome if we could utilize this, stable, constantly developing and ultimately free utlilty? Yes? Well luckly for you it’s possible. It’s been done before with the use of JavaScript, like here but those more used to scripting and desktop programming don’t worry, you can use it too.

Basically it works by sending a request to the Google translate servers which then, pretty much instantly, reply with an MP3 file which contains the requested words in their most sexy of robot voices.

Check this URL for an example of said voice – (if it doesn’t load in your browser, open VLC, CTRL+N and paste the URL in)

First, we want to be able to get python to stream an MP3 file off the web:

More info on this can be found here, the following code was is a stripped down version of the code found at


Now we want to make a string to send :

We’re going to use command line arguments as the string which wants to be read by the Google TTS engine, the following code will grab those arguments and concatenate them into a string. It also has to be in a format like a usual Google URL, these usually replace white space for the ‘+’ sign, that’s easy to do.


Now let’s just pass this URL to the bit we wrote to stream an MP3 and watch it go:

Full Source Code:

(Uses command line arguments as it’s input, run like ‘python Hello World‘)

That’s pretty much how easy it is to use Google’s free online TTS engine, one main thing to watch out for is the 100 character limit to the use of this service in this way along with the API call limits which apply to each IP address. There are loads of cool things this can be used for and I’d love to see what anyone comes up with, keep me posted and have fun!

Linux Posts Web

Downloading all your Facebook Photos for Google Plus – In Linux

Okay so, with Google Plus just being released to a select few (and invites) you might be wanting to export all your Facebook photos, tagged and albums you’ve uploaded to Google+. There are several ways of going about this, a few webapps, apps and through Facebook itself, the problem is that most of these don’t work in Linux making it a little more tricky to do without switching to Windows or OSX or borrowing some ones laptop for a while.

Through Facebook Route:

This way is actually pretty easy, which came as a surprise to me since I would have though it be in Facebooks best interest to keep users there just because it’s too much hassle to change.

First head over to, login and make your way through the labrynth that is Facebook settings to
‘Account Settings’ > Next to ‘Download Your Information’ click ‘Learn more’ > click ‘Download’.

This way you’re going to have to wait for Facebook to process all your data, they’ll then send you an e-mail once it’s done to a download link. This is a compressed (ZIP) file which contains all your information from Facebook, in the Photos folder you’ll find all your pictures which can then be uploaded to Google Plus.

The problem with this way is that it can take a reasonable amount of time (a couple of days depending on how much information you have..) and I’ve had it fail on a couple of occasions.

Alternatively you can use the following:

The PhotoGrabber Option:

For this you’ll need a couple of dependencies installed, it’s a desktop app that downloads the files for you.

Install dependencies:

sudo apt-get install python python-tk

Install PhotoGrabber:

svn checkout photograbber-read-only
cd photograbber-read-only/

Once you’ve ran all that and the ./ bit it should load up with the following:

Click Login and then proceed to login and allow PhotoGrabber to do its thing, once you’ve done that you’ll get to a screen similar to below with a code:

Copy and paste that into the PhotoGrabber window (you’ll need to use Ctrl+V no right click to paste) and then it’ll let you choose which photos to take. Once you’ve picked, hit Download and watch them download to the folder you specify. There’ll be a lot folders, one for each place you were tagged. Once it’s done you can upload them however you want to Google Plus otherwise just keep them.

HowTo Posts

HowTo: Simple Tesseract Usage Guide (OCR)


(Ubuntu 9.10)

sudo apt-get install tesseract-ocr tesseract-ocr-eng

Preparing Images for Tesseract with GIMP:

  1. Load an image with text into GIMP
  2. Image > Mode > make the image RGB or Grayscale.
  3. Tools > Color Tools > Threshold > pick a value which best shows the text
  4. Image > Mode > Indexed > choose 1-bit & no dithering.
  5. Save the image as .tif (TIFF but make sure the extension is only .tif and not .tiff)


The input file MUST be .tif (not .tiff) and the output will be a .txt (extension is automatically added by tesseract) so simply typing the following should export the input image (input.tif) as a text file (output.txt).

tesseract input.tif output


Example Output:
Hello World
Alex Sleat
Testing test
All this information was found on the following Ubuntu documentation, I just had some trouble finding it so I have re-wrote as a clean simple guide for anyone else having the same trouble. All thanks goes to whoever wrote the following link. :)