Permalink
Browse files

Enabled SSL by default, code cleanup.

  • Loading branch information...
1 parent 44770e5 commit 444c8125f3ae6911dcf26b790ca455b6558e3dce @zaf committed May 4, 2012
Showing with 19 additions and 42 deletions.
  1. +10 −10 README
  2. +8 −6 samples/speech-recog-cli.pl
  3. +1 −26 speech-recog.agi
View
20 README
@@ -11,11 +11,15 @@ Requirements
------------
Perl The Perl Programming Language
perl-libwww The World-Wide Web library for Perl
+IO-Socket-SSL Perl module that implements an interface to SSL sockets.
flac Free Lossless Audio Codec
Internet access in order to contact google and get the speech data.
-If you plan to use SSL you will need to install the 'IO-Socket-SSL' Perl module
-that implements an interface to SSL sockets.
+** Optional/Highly experimental **
+speex patent-free audio compression format designed for speech.
+ works only with patched speex encoder that supports
+ MIME "x-speex-with-header-byte"
+ https://github.com/zaf/Speex-with-header-bytes
------------
Installation
@@ -122,14 +126,10 @@ Zulu
-----------------------
Security Considerations
-----------------------
-This script contacts google's servers in order send the recorded voice data and get back
-the resulted text. If you are using voice recognition for sensitive data or you want to
-make sure that no 3rd party can eavesdrop your communication with the google service it is
-advised to enable the use of SSL in the script. This will encrypt all the traffic between
-your pbx and google servers making it much safer.
-To enable the use of SSL set the variable '$use_ssl' to 1 in the script. Keep in mind that
-security comes with a price, the initialisation of the SSL session adds a small delay in
-communication (usually under 1 sec).
+This script contacts googles' servers in order send the recorded voice data and get back
+the resulted text. The script uses SSL by default to encrypt all the traffic between
+your pbx and google servers so no 3rd party can eavesdrop your communication, but your
+voice data will be available to Google under a not yet defined policy.
-------
License
View
14 samples/speech-recog-cli.pl
@@ -24,6 +24,7 @@
use Getopt::Std;
use File::Basename;
use LWP::UserAgent;
+use LWP::ConnCache;
my %options;
my $filetype;
@@ -46,13 +47,14 @@
$ua->agent("Mozilla/5.0 (X11; Linux) AppleWebKit/535.2 (KHTML, like Gecko)");
$ua->env_proxy;
+$ua->conn_cache(LWP::ConnCache->new());
$ua->timeout(20);
# send each sound file to google and get the recognition results #
foreach my $file (@ARGV) {
my ($filename, $dir, $ext) = fileparse($file, qr/\.[^.]*/);
if ($ext ne ".flac" && $ext ne ".spx" && $ext ne ".wav") {
- say_msg("Unsupported filetype: $ext\n");
+ say_msg("Unsupported filetype: $ext");
++$error;
next;
}
@@ -72,7 +74,7 @@
$audio = do { local $/; <$fh> };
close($fh);
} else {
- say_msg("Cant read file $file.\n");
+ say_msg("Cant read file $file");
++$error;
next;
}
@@ -83,7 +85,7 @@
Content => "$audio",
);
if (!$response->is_success) {
- say_msg("Failed to get data for file:$file.\n");
+ say_msg("Failed to get data for file:$file");
++$error;
next;
}
@@ -177,16 +179,16 @@ sub encode_flac {
UNLINK => 1,
);
if (system($flac, "-8", "-f", "--totally-silent", "-o", "$tmpname", "$file")) {
- say_msg("$flac failed to encode file.");
+ say_msg("$flac failed to encode file");
return -1;
}
return $tmpname;
}
sub say_msg {
# Print messages to user if 'quiet' flag is not set #
- my $message = shift;
- warn "$0: $message" if (!defined $options{q});
+ my @message = @_;
+ warn @message if (!defined $options{q});
return;
}
View
27 speech-recog.agi
@@ -82,7 +82,7 @@ my $pro_filter = 0;
my $use_speex = 0;
# Use SSL #
-my $use_ssl = 0;
+my $use_ssl = 1;
# Verbose debugging messages #
my $debug = 0;
@@ -112,8 +112,6 @@ my $tmpdir = "/tmp";
my $host = "www.google.com/speech-api/v1/recognize";
my $flac = `/usr/bin/which flac`;
my $speex = `/usr/bin/which speexenc`;
-# ugly hardcoded path is ugly, make sure to change this #
-#my $speex = "/home/zaf/bin/speexenc";
# Store AGI input #
while (<STDIN>) {
@@ -125,11 +123,6 @@ while (<STDIN>) {
$name = " -- $AGI{request}:";
-# if ($debug) {
-# warn "$name AGI Environment Dump:\n";
-# warn "$name $_ = $AGI{$_}\n" foreach (sort keys %AGI);
-# }
-
# Abort if required programs not found. #
if ($use_speex) {
die "$name speexenc is missing. Aborting.\n" if (!$speex);
@@ -228,10 +221,6 @@ if ($debug) {
"Encoding format: ", ($use_speex) ? "speex" : "flac", "\n",
"$name Languge: $language, SSL: ", ($use_ssl) ? "yes, " : "no, ",
"$silence, Interrupt keys: $intkey\n";
-# warn "$name Playing back recorded file.\n";
-# print "STREAM FILE $tmpname \"\"\n";
-# @result = checkresponse();
-# warn "$name Failed to play file\n" if ($result[0] == -1);
}
# Encode sound data #
@@ -267,20 +256,6 @@ if ($uaresponse->content =~ /^\{"status":(\d*),"id":"(.*)","hypotheses":\[(.*)\]
$response{status} = "$1";
$response{id} = "$2";
warn "$name Error reading audio file\n" if ($response{status} != 0);
-# # Save voice samples for debugging purposes #
-# if ($use_speex && $debug) {
-# if ($response{status} == 0) {
-# move("$tmpname.spx", "$tmpname-success.spx");
-# } else {
-# move("$tmpname.spx", "$tmpname-fail.spx");
-# }
-# } elsif (!$use_speex && $debug) {
-# if ($response{status} == 0) {
-# move("$tmpname.flac", "$tmpname-success.flac");
-# } else {
-# move("$tmpname.flac", "$tmpname-fail.flac");
-# }
-# }
if ($3 =~ /^\{"utterance":"(.*)","confidence":(.*)\}/) {
$response{utterance} = "$1";

0 comments on commit 444c812

Please sign in to comment.