From e8c947163e87bfda3abc7840d04edfa4d154c198 Mon Sep 17 00:00:00 2001 From: Brian West Date: Sat, 28 Feb 2009 16:09:38 +0000 Subject: [PATCH] example of using esl to get events for ASR git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12344 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- libs/esl/perl/server3.pl | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 libs/esl/perl/server3.pl diff --git a/libs/esl/perl/server3.pl b/libs/esl/perl/server3.pl new file mode 100644 index 0000000000..e3e8c102f9 --- /dev/null +++ b/libs/esl/perl/server3.pl @@ -0,0 +1,61 @@ +require ESL; +use IO::Socket::INET; + +#ESL::eslSetLogLevel(7); + +my $ip = "127.0.0.1"; +my $sock = new IO::Socket::INET ( LocalHost => $ip, LocalPort => '8040', Proto => 'tcp', Listen => 1, Reuse => 1 ); +die "Could not create socket: $!\n" unless $sock; + +for(;;) { + my $new_sock = $sock->accept(); + my $pid = fork(); + if ($pid) { + close($new_sock); + next; + } + + my $host = $new_sock->sockhost(); + my $fd = fileno($new_sock); + + my $con = new ESL::ESLconnection($fd); + my $info = $con->getInfo(); + + #print $info->serialize(); + my $uuid = $info->getHeader("unique-id"); + + printf "Connected call %s, from %s\n", $uuid, $info->getHeader("caller-caller-id-number"); + + $con->sendRecv("myevents"); + $con->execute("answer"); + $con->sendRecv("divert_events on"); + $con->execute("detect_speech", "pocketsphinx yes_no yes_no"); + $con->execute("playback", "/ram/swimp.raw"); + + while($con->connected()) { + #my $e = $con->recvEventTimed(100); + my $e = $con->recvEvent(); + + if ($e) { + my $name = $e->getHeader("event-name"); + print "EVENT [$name]\n"; + if ($name eq "DETECTED_SPEECH") { + print $e->serialize(); + my $type = $e->getHeader("speech-type"); + if ($type = "detected-speech") { + $con->execute("detect_speech", "resume"); + } + } + if ($name eq "DTMF") { + my $digit = $e->getHeader("dtmf-digit"); + my $duration = $e->getHeader("dtmf-duration"); + print "DTMF digit $digit ($duration)\n"; + } + } + } + + print "BYE\n"; + close($new_sock); +} + +