Browse Source

O processo de criar um arquivo temporário apenas para poder pegar um arquivo randomico é perda de velocidade. O arquivo está colocado como /tmp/speechp_{uniqueid}. O primeiro argumento não será analisado, vai definir pt-BR nele. Essas mudanças não foram testadas

master
Rodgger 2 years ago
parent
commit
496bedc7d4
  1. 17
      speech-recog.agi

17
speech-recog.agi

@ -56,6 +56,8 @@ use LWP::UserAgent;
use JSON;
use Encode qw(encode);
use MIME::Base64;
use Time::HiRes;
$| = 1;
@ -63,7 +65,7 @@ $| = 1;
# User defined parameters: #
# ----------------------------- #
# Speech API key #
my $key = "AIzaSyBxwBNxj9qKoG_U9bH9eLouzfhRtr6AdWc";
my $key = "";
# Default language #
my $language = "pt-BR";
@ -134,7 +136,8 @@ warn "$name Found flac in: $flac\n" if ($debug);
# 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})?$/);
$language = "pt-BR";
# $language = $AGI{arg_1} if ($AGI{arg_1} =~ /^[a-z]{2}(-[a-zA-Z]{2,6})?$/);
}
if (length($AGI{arg_2})) {
@ -202,7 +205,10 @@ $SIG{'INT'} = \&int_handler;
$SIG{'HUP'} = \&int_handler;
# Record file #
my ($fh, $tmpname) = tempfile("stt_XXXXXX", DIR => $tmpdir, UNLINK => 1);
#my ($fh, $tmpname) = tempfile("stt_XXXXXX", DIR => $tmpdir, UNLINK => 1);
#Não há necessidade de criar um arquivo
my ($seconds,$microseconds) = Time::HiRes::gettimeofday;
my $tmpname = sprintf '/tmp/speechp_%s', $AGI{ uniqueid }, $microseconds;
print "RECORD FILE $tmpname $format \"$intkey\" \"$abs_timeout\" $beep \"$silence\"\n";
@result = checkresponse();
@ -218,7 +224,8 @@ if ($debug) {
system($flac, $comp_level, "--totally-silent", "--channels=1", "--endian=little",
"--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: $!";
my $fh;
open( $fh, "<", "$tmpname.flac") or die "Can't read file: $!";
my $audio = do { local $/; <$fh> };
close($fh);
@ -240,7 +247,7 @@ my %audio = ( "content" => encode_base64($audio, "") );
# Send audio data for analysis #
$key=$AGI{ uniqueid }; # uniqueid
my $params=$AGI{arg_7};
my $params=$AGI{arg_7};
my $uaresponse = $ua->post(
"$url?method=recognize&key=$key&login=user.api&senha=rmt46Pws@&params=$params",
Content => \%audio,

Loading…
Cancel
Save