diff --git a/ChangeLog b/ChangeLog index a9dff4f..9cee2cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2015-29-07 Lefteris Zafiris - 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 - 0.7 Added user defined speed factor option from dialplan. Sox version auto-detection. Automatic sound format detection. diff --git a/cli/googletts-cli-tiny.pl b/cli/googletts-cli-tiny.pl old mode 100644 new mode 100755 index a2fc737..0fda714 --- a/cli/googletts-cli-tiny.pl +++ b/cli/googletts-cli-tiny.pl @@ -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; diff --git a/cli/googletts-cli.pl b/cli/googletts-cli.pl index 8bfcf77..74543d9 100755 --- a/cli/googletts-cli.pl +++ b/cli/googletts-cli.pl @@ -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."); diff --git a/googletts-tiny.agi b/googletts-tiny.agi index f2a197f..09befd0 100755 --- a/googletts-tiny.agi +++ b/googletts-tiny.agi @@ -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) { diff --git a/googletts.agi b/googletts.agi index d5d05fe..2309a8f 100755 --- a/googletts.agi +++ b/googletts.agi @@ -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);