Permalink
Browse files

Compatibility fixes for the updated translate page.

  • Loading branch information...
zaf committed Jul 29, 2015
1 parent a17b606 commit ee23da1863a47733bef6a2aa57d3947787ca9985
Showing with 43 additions and 14 deletions.
  1. +9 −0 ChangeLog
  2. +9 −4 cli/googletts-cli-tiny.pl
  3. +8 −3 cli/googletts-cli.pl
  4. +9 −4 googletts-tiny.agi
  5. +8 −3 googletts.agi
View
@@ -1,3 +1,12 @@
+2015-29-07 Lefteris Zafiris <zaf.000@gmail.com> - 0.8
+ Compatibility fixes for the updated translate page.
+ Set default speed factor to 1. Small changes to cache path handling.
+ Fixed UTF handling and URL escaping. Updated text splitting function,
+ char limit seems to be 99 for some languages.
+ Enabled sox auto-detection by default.
+ Added SSL support and made it the default.
+ Added 'tiny' versions of the tts scripts.
+
2012-30-09 Lefteris Zafiris <zaf.000@gmail.com> - 0.7
Added user defined speed factor option from dialplan.
Sox version auto-detection. Automatic sound format detection.
View
13 cli/googletts-cli-tiny.pl 100644 → 100755
@@ -25,7 +25,7 @@
my $input;
my $url;
my $http;
-my $use_ssl = 0;
+my $use_ssl = 1;
my $speed = 1;
my $lang = "en-US";
my $tmpdir = "/tmp";
@@ -67,14 +67,14 @@
if ($use_ssl) {
$url = "https://" . $host;
$http = HTTP::Tiny->new(
- agent => 'Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101',
+ agent => 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36',
timeout => $timeout,
verify_SSL => 1,
);
} else {
$url = "http://" . $host;
$http = HTTP::Tiny->new(
- agent => 'Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101',
+ agent => 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36',
timeout => $timeout,
);
}
@@ -91,7 +91,12 @@
SUFFIX => ".mp3",
UNLINK => 1
);
- my $response = $http->mirror("$url?tl=$lang&q=$line", $mp3_name);
+ my $headers = {
+ 'Accept' => 'audio/webm,audio/ogg,audio/wav,audio/*;q=0.9,application/ogg;q=0.7,video/*;q=0.6,*/*;q=0.5',
+ 'Referer' => 'https://translate.google.co.uk/',
+ 'Accept-Language' => 'en-US,en;q=0.5',
+ };
+ my $response = $http->mirror("$url?ie=UTF-8&q=$line&tl=$lang&total=1&idx=0&client=t", $mp3_name, $headers);
if (!$response->{success}) {
say_msg("Failed to fetch speech data.");
exit 1;
View
@@ -26,7 +26,7 @@
my $input;
my $url;
my $ua;
-my $use_ssl = 0;
+my $use_ssl = 1;
my $speed = 1;
my $lang = "en-US";
my $tmpdir = "/tmp";
@@ -72,7 +72,7 @@
$url = "http://" . $host;
$ua = LWP::UserAgent->new;
}
-$ua->agent("Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101");
+$ua->agent("Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36");
$ua->env_proxy;
$ua->conn_cache(LWP::ConnCache->new());
$ua->timeout($timeout);
@@ -89,7 +89,12 @@
SUFFIX => ".mp3",
UNLINK => 1
);
- my $request = HTTP::Request->new('GET' => "$url?tl=$lang&q=$line");
+ my $request = HTTP::Request->new('GET' => "$url?ie=UTF-8&q=$line&tl=$lang&total=1&idx=0&client=t");
+ $request->header(
+ 'Accept' => 'audio/webm,audio/ogg,audio/wav,audio/*;q=0.9,application/ogg;q=0.7,video/*;q=0.6,*/*;q=0.5',
+ 'Referer' => 'https://translate.google.co.uk/',
+ 'Accept-Language' => 'en-US,en;q=0.5',
+ );
my $response = $ua->request($request, $mp3_name);
if (!$response->is_success) {
say_msg("Failed to fetch speech data.");
View
@@ -163,14 +163,14 @@ else { ($fexten, $samplerate) = ("sln", 8000); }
if ($use_ssl) {
$url = "https://" . $host;
$http = HTTP::Tiny->new(
- agent => 'Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101',
+ agent => 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36',
timeout => $timeout,
verify_SSL => 1,
);
} else {
$url = "http://" . $host;
$http = HTTP::Tiny->new(
- agent => 'Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101',
+ agent => 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36',
timeout => $timeout,
);
}
@@ -195,14 +195,19 @@ foreach my $line (@text) {
}
}
$line = uri_escape($line);
- warn "$name URL passed: $url?tl=$lang&q=$line\n" if ($debug);
+ warn "$name URL passed: $url?ie=UTF-8&q=$line&tl=$lang&total=1&idx=0&client=t\n" if ($debug);
# Hnadle interrupts #
$SIG{'INT'} = \&int_handler;
$SIG{'HUP'} = \&int_handler;
($fh, $tmpname) = tempfile("ggl_XXXXXX", DIR => $tmpdir, UNLINK => 1);
- my $response = $http->mirror("$url?tl=$lang&q=$line", $tmpname);
+ my $headers = {
+ 'Accept' => 'audio/webm,audio/ogg,audio/wav,audio/*;q=0.9,application/ogg;q=0.7,video/*;q=0.6,*/*;q=0.5',
+ 'Referer' => 'https://translate.google.co.uk/',
+ 'Accept-Language' => 'en-US,en;q=0.5',
+ };
+ my $response = $http->mirror("$url?ie=UTF-8&q=$line&tl=$lang&total=1&idx=0&client=t", $tmpname, $headers);
die "$name Failed to fetch file.\n" unless ($response->{success});
# Detect required programs #
if (!$sox || !$mpg123) {
View
@@ -174,7 +174,7 @@ if ($use_ssl) {
$url = "http://" . $host;
$ua = LWP::UserAgent->new;
}
-$ua->agent("Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101");
+$ua->agent("Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36");
$ua->env_proxy;
$ua->conn_cache(LWP::ConnCache->new());
$ua->timeout($timeout);
@@ -199,14 +199,19 @@ foreach my $line (@text) {
}
}
$line = uri_escape($line);
- warn "$name URL passed: $url?tl=$lang&q=$line\n" if ($debug);
+ warn "$name URL passed: $url?ie=UTF-8&q=$line&tl=$lang&total=1&idx=0&client=t\n" if ($debug);
# Hnadle interrupts #
$SIG{'INT'} = \&int_handler;
$SIG{'HUP'} = \&int_handler;
($fh, $tmpname) = tempfile("ggl_XXXXXX", DIR => $tmpdir, UNLINK => 1);
- my $ua_request = HTTP::Request->new('GET' => "$url?tl=$lang&q=$line");
+ my $ua_request = HTTP::Request->new('GET' => "$url?ie=UTF-8&q=$line&tl=$lang&total=1&idx=0&client=t");
+ $ua_request->header(
+ 'Accept' => 'audio/webm,audio/ogg,audio/wav,audio/*;q=0.9,application/ogg;q=0.7,video/*;q=0.6,*/*;q=0.5',
+ 'Referer' => 'https://translate.google.co.uk/',
+ 'Accept-Language' => 'en-US,en;q=0.5',
+ );
my $ua_response = $ua->request($ua_request, $tmpname);
die "$name Failed to fetch file.\n" unless ($ua_response->is_success);

0 comments on commit ee23da1

Please sign in to comment.