Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Small fix in audio format detection.
  • Loading branch information
zaf committed May 19, 2012
1 parent c7c0b0b commit 986d282
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions speech-recog.agi
Expand Up @@ -185,14 +185,13 @@ if ($result[0] == 4) {
}

# 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;
}
if ($samplerate == 0) { ($format, $samplerate) = detect_format(); }
elsif ($samplerate == 12000) { $format = "sln12"; }
elsif ($samplerate == 16000) { $format = "sln16"; }
elsif ($samplerate == 32000) { $format = "sln32"; }
elsif ($samplerate == 44100) { $format = "sln44"; }
elsif ($samplerate == 48000) { $format = "sln48"; }
else { ($format, $samplerate) = ("sln", 8000); }

# Initialise User angent #
if ($use_ssl) {
Expand Down Expand Up @@ -286,34 +285,36 @@ sub checkresponse {
$input =~ /result=(-?\d+)\s?(.*)$/;
if (!length($1)) {
warn "$name Command failed: $input\n";
@values = ("-1");
@values = (-1, -1);
} else {
warn "$name Command returned: $input\n" if ($debug);
@values = ("$1", "$2");
}
} else {
warn "$name Unexpected result: $input\n";
@values = ("-1");
@values = (-1, -1);
}
return @values;
}

sub detect_format {
my @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);
if ($reply[1] =~ /silk12|sln12/) {
@format = ("sln12", 12000);
} elsif ($reply[1] =~ /g722|speex16|slin16|silk16|siren7/) {
@format = ("sln16", 16000);
} elsif ($reply[1] =~ /speex32|slin32|celt32|siren14/) {
@format = ("sln32", 32000);
} elsif ($reply[1] =~ /celt44|slin44/) {
@format = ("sln44", 44100);
} elsif ($reply[1] =~ /celt48|slin48/) {
@format = ("sln48", 48000);
} else {
return ("sln", 8000);
@format = ("sln", 8000);
}
return @format;
}

sub int_handler {
Expand Down

0 comments on commit 986d282

Please sign in to comment.