Skip to content

Commit

Permalink
Compatibility fixes for the updated translate page.
Browse files Browse the repository at this point in the history
  • Loading branch information
zaf committed Jul 29, 2015
1 parent a17b606 commit ee23da1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
@@ -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.
Expand Down
13 changes: 9 additions & 4 deletions cli/googletts-cli-tiny.pl 100644 → 100755
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
);
}
Expand All @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions cli/googletts-cli.pl
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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.");
Expand Down
13 changes: 9 additions & 4 deletions googletts-tiny.agi
Expand Up @@ -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,
);
}
Expand All @@ -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) {
Expand Down
11 changes: 8 additions & 3 deletions googletts.agi
Expand Up @@ -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);
Expand All @@ -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);

Expand Down

0 comments on commit ee23da1

Please sign in to comment.