Skip to content

Commit

Permalink
Removed sox related code.
Browse files Browse the repository at this point in the history
Sox is no longer an option for sound conversion.
Tests failed to show any improvements in detection rates when
sox is used for normalising sound data.
  • Loading branch information
zaf committed Jan 18, 2012
1 parent 58a760c commit 44286e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
9 changes: 3 additions & 6 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ 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.

The script can optionally use sox for sound conversion. It works with recent
versions of sox (It will not work in RHEL/Centos 5).

------------
Installation
------------
Expand Down Expand Up @@ -52,15 +49,15 @@ sample dialplan code for your extensions.conf
;Simple speech recognition
exten => 1234,1,Answer()
exten => 1234,n,agi(speech-recog.agi,en-US)
exten => 1234,n,Noop(== The text you just said is: ${utterance} ==)
exten => 1234,n,Noop(== The probability to be right is: ${confidence} ==)
exten => 1234,n,Verbose(1,The text you just said is: ${utterance})
exten => 1234,n,Verbose(1,The probability to be right is: ${confidence})
exten => 1234,n,Hangup()

;Speech recognition demo also using googletts.agi for text to speech synthesis:
exten => 1235,1,Answer()
exten => 1235,n,agi(googletts.agi,"Say something in English, when done press the pound key.",en)
exten => 1235,n(record),agi(speech-recog.agi,en-US)
exten => 1235,n,Noop(= Script returned: ${status} , ${id} , ${confidence} , ${utterance} =)
exten => 1235,n,Verbose(1,Script returned: ${status} , ${id} , ${confidence} , ${utterance})

;Check return status:
exten => 1235,n,GotoIf($["${status}" = "0"]?success:fail)
Expand Down
33 changes: 7 additions & 26 deletions speech-recog.agi
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
# Default language: $language
# Sample rate: $samplerate (value in Hz, 8000 or 16000 if used with wideband codecs)
# SSL: $use_ssl (0: disable, 1: enable)
# Enable sox: $use_sox (0: disable, 1: enable)
# Normalizing level: $gain (value in db, applicable only if sox is enabled)
#

use warnings;
Expand All @@ -55,12 +53,6 @@ my $samplerate = 8000;
# Use SSL #
my $use_ssl = 0;

# Use sox for sound encoding #
my $use_sox = 0;

# Max sound power gain in dB #
my $gain = -5;

# Verbose debugging messages #
my $debug = 0;

Expand All @@ -86,7 +78,6 @@ my $timeout = 10000;
my $tmpdir = "/tmp";
my $filetype = "x-flac";
my $host = "www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium";
my $sox = `/usr/bin/which sox`;
my $flac = `/usr/bin/which flac`;

# Check endianness #
Expand All @@ -107,11 +98,10 @@ while (<STDIN>) {
$name = " -- $AGI{request}:";

# Abort if required programs not found. #
die "$name sox is missing. Aborting.\n" if (!$sox && $use_sox);
die "$name flac is missing. Aborting.\n" if (!$flac && !$use_sox);
die "$name flac is missing. Aborting.\n" if (!$flac);

chomp($sox, $flac);
print STDERR "$name Found sox in: $sox, flac in: $flac\n" if ($debug);
chomp($flac);
print STDERR "$name Found flac in: $flac\n" if ($debug);

# Setting recording file format according to sample rate. #
if ($samplerate == 16000) {
Expand Down Expand Up @@ -183,19 +173,10 @@ if ($debug) {
}

# Encode file to flac. #
if ($use_sox) {
# Covert file using sox, normalizing to -5db and removing possible DC offset. #
system($sox, "-b", "16", "-t", "raw", "-r", $samplerate, "-e", "signed-integer",
"--endian", $endian, "$tmpname.$format", "$tmpname.flac", "norm", $gain,
"highpass", "10") == 0
or die "$name $sox failed: $?\n";
} else {
# Convert sound file using flac. #
system($flac, $comp_level, "--totally-silent", "--channels=1", "--endian=$endian",
"--sign=signed", "--bps=16", "--force-raw-format", "--sample-rate=$samplerate",
"$tmpname.$format") == 0
or die "$name $flac failed: $?\n";
}
system($flac, $comp_level, "--totally-silent", "--channels=1", "--endian=$endian",
"--sign=signed", "--bps=16", "--force-raw-format", "--sample-rate=$samplerate",
"$tmpname.$format") == 0
or die "$name $flac failed: $?\n";

open($fh, "<", "$tmpname.flac") or die "Can't read file: $!";
$audio = do { local $/; <$fh> };
Expand Down

0 comments on commit 44286e8

Please sign in to comment.