Permalink
Browse files

Added SSL support

  • Loading branch information...
1 parent a18c715 commit a4b9f69ec499fa0b5b471afb679bf212840ab143 @zaf committed Feb 15, 2014
Showing with 42 additions and 6 deletions.
  1. +8 −0 README
  2. +18 −3 cli/googletts-cli.pl
  3. +16 −3 googletts.agi
View
8 README
@@ -202,6 +202,14 @@ Yiddish: yi
Yoruba: yo
Zulu: zu
+-----------------------
+Security Considerations
+-----------------------
+This script contacts googles' servers in order to get voice data.
+The script can SSL to encrypt all the traffic between your pbx and google servers
+so no 3rd party can eavesdrop your communication, but your data will be available
+to Google under a not yet defined policy.
+
-------
License
-------
View
@@ -25,17 +25,20 @@
my @soxargs;
my $samplerate;
my $input;
+my $url;
+my $ua;
+my $use_ssl = 0;
my $speed = 1;
my $lang = "en-US";
my $tmpdir = "/tmp";
my $timeout = 10;
-my $url = "http://translate.google.com/translate_tts";
+my $host = "translate.google.com/translate_tts";
my $mpg123 = `/usr/bin/which mpg123`;
my $sox = `/usr/bin/which sox`;
VERSION_MESSAGE() if (!@ARGV);
-getopts('o:l:r:t:f:s:hqv', \%options);
+getopts('o:l:r:t:f:s:heqv', \%options);
# Dislpay help messages #
VERSION_MESSAGE() if (defined $options{h});
@@ -62,7 +65,14 @@
@text = /.{1,99}[.,?!:;]|.{1,99}\s/g;
}
-my $ua = LWP::UserAgent->new;
+# Initialise User angent #
+if ($use_ssl) {
+ $url = "https://" . $host;
+ $ua = LWP::UserAgent->new(ssl_opts => {verify_hostname => 1});
+} else {
+ $url = "http://" . $host;
+ $ua = LWP::UserAgent->new;
+}
$ua->agent("Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101");
$ua->env_proxy;
$ua->conn_cache(LWP::ConnCache->new());
@@ -153,6 +163,10 @@ sub parse_options {
$options{s} =~ /\d+/ ? $speed = $options{s}
: say_msg("Invalind speed factor, using default.");
}
+ # set SSL encryption #
+ if (defined $options{e}) {
+ $use_ssl = 1;
+ }
return;
}
@@ -167,6 +181,7 @@ sub VERSION_MESSAGE {
" -r <rate> specify the output sampling rate in Hertz (default 22050)\n",
" -s <factor> specify the output speed factor\n",
" -q quiet (Don't print any messages or warnings)\n",
+ " -e use SSL for encryption\n",
" -h this help message\n",
" -v suppoted languages list\n\n",
"Examples:\n",
View
@@ -30,6 +30,7 @@
# Chace: $usecache
# Chache directory: $cachedir
# SoX Version: $sox_ver
+# SSL encryption: $use_ssl
#
use warnings;
@@ -68,6 +69,9 @@ my $samplerate = "";
# Leave blank to auto-detect #
my $sox_ver = "";
+# Use SSL for encryption #
+my $use_ssl = 0;
+
# Verbose debugging messages #
my $debug = 0;
@@ -83,11 +87,12 @@ my $filename;
my $fexten;
my @result;
my $name;
+my $url;
my $intkey = "";
my $tmpdir = "/tmp";
my $maxlen = 4096;
my $timeout = 10;
-my $url = "http://translate.google.com/translate_tts";
+my $host = "translate.google.com/translate_tts";
my $sox = `/usr/bin/which sox`;
my $mpg123 = `/usr/bin/which mpg123`;
@@ -166,7 +171,15 @@ elsif ($samplerate == 44100) { $fexten = "sln44"; }
elsif ($samplerate == 48000) { $fexten = "sln48"; }
else { ($fexten, $samplerate) = ("sln", 8000); }
-$ua = LWP::UserAgent->new;
+
+# Initialise User angent #
+if ($use_ssl) {
+ $url = "https://" . $host;
+ $ua = LWP::UserAgent->new(ssl_opts => {verify_hostname => 1});
+} else {
+ $url = "http://" . $host;
+ $ua = LWP::UserAgent->new;
+}
$ua->agent("Mozilla/5.0 (X11; Linux i686; rv:27.0) Gecko/20100101");
$ua->env_proxy;
$ua->conn_cache(LWP::ConnCache->new());
@@ -175,7 +188,7 @@ $ua->timeout($timeout);
foreach my $line (@text) {
$line = encode('utf8', $line);
$line =~ s/^\s+|\s+$//g;
- last if (length($line) == 0);
+ next if (length($line) == 0);
if ($debug) {
warn "$name Text passed for synthesis: $line\n",
"$name Language: $lang, Interrupt keys: $intkey, Sample rate: $samplerate\n",

0 comments on commit a4b9f69

Please sign in to comment.