Translation Practice With Twitter and Google Translate


During a conversation with a friend about learning another language, he said he had progressed to the point where he was able to read some tweets. This got me thinking.

Twitter is a great source for interesting fragments of text. In order to assist with the translation effort, I thought I could hook up Twitter and Google translate, so that you have an opportunity to see what Google thinks the translation actually is, and give you some feedback on your effort.

OSX has a command named say built in, which is capable of reading out inputted text. This seemed like a good starting point. However, I then discovered the google-translate gem I was using supports speaking the translation by asking Google to generate the sound file and plays the result through afplay.

A short time elapsed while I glued the twitter and google-translate gems together (yay Ruby!) and the result is below.

The script does a search of Twitter for tweets in the given language. It then presents them to you one by one, printing the tweet and reading it out. You then have an opportunity to enter your translation before the Google translate result is shown.

The twitter language identifiction is not perfect, so sometimes you get tweets in the wrong language. You can enter ’n’ to skip the tweet when asked for a translation.

PS if you want to experiment with the voices available to the say command, the following bash script will read the sentence in the $text variable in each available voice.

IFS=$'\n'
voices=(`say -v "?" | cut -c 1-20`)

text="Hello, this is your computer speaking!"

for v in "${voices[@]}"
do
	v=`echo $v| xargs`
	echo "Using voice '$v'"
	say -v "$v" "$text"
done