Skip to content

Commit

Permalink
Added SSL support
Browse files Browse the repository at this point in the history
  • Loading branch information
zaf committed Feb 15, 2014
1 parent a18c715 commit a4b9f69
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
21 changes: 18 additions & 3 deletions cli/googletts-cli.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand All @@ -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());
Expand Down Expand Up @@ -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;
}

Expand All @@ -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",
Expand Down
19 changes: 16 additions & 3 deletions googletts.agi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# Chace: $usecache
# Chache directory: $cachedir
# SoX Version: $sox_ver
# SSL encryption: $use_ssl
#

use warnings;
Expand Down Expand Up @@ -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;

Expand All @@ -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`;

Expand Down Expand Up @@ -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());
Expand All @@ -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",
Expand Down

0 comments on commit a4b9f69

Please sign in to comment.