Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added automatic audio format detection.

  • Loading branch information...
commit c7c0b0b707a0526175ba7e18c5bf9c52a85a5b3e 1 parent 444c812
@zaf authored
Showing with 42 additions and 21 deletions.
  1. +42 −21 speech-recog.agi
View
63 speech-recog.agi
@@ -38,7 +38,8 @@
# $intkey (can be any digit from 0 to 9 or # and *, or a combination of them)
#
# Sample rate:
-# $samplerate (value in Hz, 8000 or 16000 if used with wideband codecs)
+# $samplerate (value in Hz. 0 for atuomatic detection per channel/call, 16000 for
+# use with wideband codecs, 8000 for traditional codecs.
#
# Profanity filter:
# $pro_filter (0:disable, 1: remove profanities, 2: mask profanities)
@@ -73,7 +74,7 @@ my $timeout = 2;
my $intkey = "#";
# Input audio sample rate #
-my $samplerate = 8000;
+my $samplerate = 0;
# Profanity filter #
my $pro_filter = 0;
@@ -123,6 +124,19 @@ while (<STDIN>) {
$name = " -- $AGI{request}:";
+# Reset variables. #
+%response = (
+ utterance => -1,
+ status => -1,
+ id => -1,
+ confidence => -1,
+);
+warn "$name Clearing channel variables.\n" if ($debug);
+foreach (keys %response) {
+ print "SET VARIABLE \"$_\" \"$response{$_}\"\n";
+ checkresponse();
+}
+
# Abort if required programs not found. #
if ($use_speex) {
die "$name speexenc is missing. Aborting.\n" if (!$speex);
@@ -134,14 +148,6 @@ if ($use_speex) {
warn "$name Found flac in: $flac\n" if ($debug);
}
-# Setting recording file format according to sample rate. #
-if ($samplerate == 16000) {
- $format = "sln16";
-} else {
- $format = "sln";
- $samplerate = 8000;
-}
-
# Setting language, timeout, interrupt keys and BEEP indication #
if (length($AGI{arg_1})) {
$language = $AGI{arg_1} if ($AGI{arg_1} =~ /^[a-z]{2}(-[a-zA-Z]{2,6})?$/);
@@ -178,17 +184,14 @@ if ($result[0] == 4) {
checkresponse();
}
-# Reset variables. #
-%response = (
- utterance => -1,
- status => -1,
- id => -1,
- confidence => -1,
-);
-warn "$name Clearing channel variables.\n" if ($debug);
-foreach (keys %response) {
- print "SET VARIABLE \"$_\" \"$response{$_}\"\n";
- checkresponse();
+# Setting recording file format according to sample rate. #
+if ($samplerate == 0) {
+ ($format, $samplerate) = detect_format();
+} elsif ($samplerate == 16000) {
+ $format = "sln16";
+} else {
+ $format = "sln";
+ $samplerate = 8000;
}
# Initialise User angent #
@@ -295,6 +298,24 @@ sub checkresponse {
return @values;
}
+sub detect_format {
+ print "GET FULL VARIABLE \${CHANNEL(audionativeformat)}\n";
+ my @reply = checkresponse();
+ if ($reply[0] == 1 && $reply[1] =~ /silk12|sln12/) {
+ return ("sln12", 12000);
+ } elsif ($reply[0] == 1 && $reply[1] =~ /g722|speex16|slin16|silk16|siren7/) {
+ return ("sln16", 16000);
+ } elsif ($reply[0] == 1 && $reply[1] =~ /speex32|slin32|celt32|siren14/) {
+ return ("sln32", 32000);
+ } elsif ($reply[0] == 1 && $reply[1] =~ /celt44|slin44/) {
+ return ("sln44", 44100);
+ } elsif ($reply[0] == 1 && $reply[1] =~ /celt48|slin48/) {
+ return ("sln48", 48000);
+ } else {
+ return ("sln", 8000);
+ }
+}
+
sub int_handler {
die "$name Interrupt signal received, terminating...\n";
}
Please sign in to comment.
Something went wrong with that request. Please try again.