Up until the Violet platform was switched off, we were using our Nabaztag to read out alarms from our Nagios monitoring system. Since NabAlive came about I've been looking to set this back up again, but only having French TTS was causing our English status messages to be somewhat unintelligable.
I decided to have another look at this as we've got a platform change freeze at the moment, and it's much easier to do than I was expecting. It turns out Google Translate has a text to speech facility where you can send it a string and it returns an MP3, here's an example:
http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=Hello+World
You can paste this directly into the TTS box in the nabaztag.com actions interface, and the MP3 returned is read out by your Nabaztag.
But if you want to script this, pasting into a browser isn't much use, so here is what happens behind the scenes when you submit the URL:
http://www.nabaztag.com/nabaztags/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/play?url=http%3A%2F%2Ftranslate.google.com%2Ftranslate_tts%3Fie%3DUTF-8%26tl%3Den%26q%3Dhello%2Bworld
where xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is the API key for your rabbit.
This lead on to me putting together a quick script in Perl to do the encoding and post the request for me:
- Code:
-
#! /usr/bin/perl
# send_nabaztag_tts.pl - Provides English Text to speech for your Nabaztag on the NabAlive platform via Google Translate
# (C)2012 Gareth Davis - No rights reserved - This script is freely distributable
use LWP;
use HTTP::Request::Common;
use URI::Escape;
my $browser = LWP::UserAgent->new;
if ( @ARGV[0] eq "" || @ARGV[1] eq "" )
{
die "USAGE: $0 Token Message\n";
}
my $token = @ARGV[0];
my $text = @ARGV[1];
my $baseurl='http://www.nabaztag.com/nabaztags/'.$token.'/play?url=http%3A%2F%2Ftranslate.google.com%2Ftranslate_tts%3Fie%3DUTF-8%26tl%3Den%26q%3D';
my $encodedtext = uri_escape($text);
$encodedtext=~s/%20/%2B/gi;
$url = $baseurl.$encodedtext;
print "Requesting $url\n";
my $response = $browser->get( $url );
if (!$response->is_success) {
print "FAIL: ".$response->content;
}
You then call the Perl script with:
- Code:
-
send_nabaztag_tts.pl xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx "Hello World"
I worked this out by sniffing the web transactions going backwards and forward between the web browser and nabaztag.com, so this probably isn't officially supported. I did try using the official API, but kept getting Error 500 messages for reasons I didn't understand.
Although the Google Translate TTS API is in beta, it supports a number of languages other than English. You would need to play with the
tl=en perameter in the URL to switch to another language.
Enjoy!