Get key press in loop

while(){ //To loop through list of questions No. 1,2,3,4,5,6…
$count=0;
while($count < 3){
$count++;
if($ansType == 1){ //if question require key press
$result = $agi->get_data(‘beep’, 3000, 2);

  $keys = $result['result'];

}elseif($ansType == 2){ //if voice response
$agi->record_file("/var/lib/asterisk/agi-bin/survey_sound/aans.$countquest",“wav”,’’,-1,null,true,2);
include(‘voicetotext_survey.php’);

}

}

}

The problem I have is that when it gets to question number 3 then, it does not wait 3000milsec for key pressPreformatted text

Please edit your post and place your snippet within 'Preformatted text' tags.

Please include console output in 'Preformatted text' tags after:

core set verbose 3 (or higher)
agi set debug on

The only thing that relates to the number 3, in that code, is $count, but that is only referenced for the number of iterations, and there is nothing that would distinguish iteration two from iteration 3.

There is one branch that has included code which isn’t visible

(It also appears that it tries to read the same information three times, even if it gets it on the first attempt.)

From the output debug below:
Quest 1 requires key pres, question 2 voice response, question 3 key press
first it plays the welcome message, then After the first and second question in the sound file it did wait for the delay after the beep, but in the third question it did not wait. Note that I end the call after the fail to wait in this question three.

Also am seeing the number 99981 in this debug output? Strange that this number is recorded as my key-press in question 6. please note that question 4 and 5 requires voice response.

I notice that when I comments out this two lines below which record and process the voice response with google Speech To Text, all the key press works fine.
$agi->record_file("/var/lib/asterisk/agi-bin/survey_sound/aans.$countquest",“wav”,’’,-1,null,true,2);
include(‘voicetotext_survey.php’);

Here is the output debug:
<SIP/john-00000000>AGI Rx << ANSWER
<SIP/john-00000000>AGI Tx >> 200 result=0
> 0x7fa6d8005e50 – Strict RTP learning complete - Locking on source address 192.168.43.1:34080
<SIP/john-00000000>AGI Rx << EXEC Playback /path-to-sound-file/1
– AGI Script Executing Application: (Playback) Options: (/path-to-sound-file/1)
– <SIP/john-00000000> Playing ‘/path-to-sound-file/1.slin’ (language ‘en’)
<SIP/john-00000000>AGI Tx >> 200 result=0
<SIP/john-00000000>AGI Rx << EXEC Playback /path-to-sound-file/1
– AGI Script Executing Application: (Playback) Options: (/path-to-sound-file/1)
– <SIP/john-00000000> Playing ‘/path-to-sound-file/1.slin’ (language ‘en’)
<SIP/john-00000000>AGI Tx >> 200 result=0
<SIP/john-00000000>AGI Rx << GET DATA beep 3000 2
– <SIP/john-00000000> Playing ‘beep.gsm’ (language ‘en’)
<SIP/john-00000000>AGI Tx >> 200 result=2 (timeout)
<SIP/john-00000000>AGI Rx << EXEC Playback /path-to-sound-file/1
– AGI Script Executing Application: (Playback) Options: (/path-to-sound-file/1)
– <SIP/john-00000000> Playing ‘/path-to-sound-file/1.slin’ (language ‘en’)
<SIP/john-00000000>AGI Tx >> 200 result=0
<SIP/john-00000000>AGI Rx << RECORD FILE /path-to-sound-file/aans.2 wav “” -1 BEEP s=2
– <SIP/john-00000000> Playing ‘beep.gsm’ (language ‘en’)
<SIP/john-00000000>AGI Tx >> 200 result=99981 (timeout) endpos=38080
<SIP/john-00000000>AGI Rx << Transcript: number 2 number 2 test number 2
<SIP/john-00000000>AGI Tx >> 510 Invalid or unknown command
<SIP/john-00000000>AGI Rx << Confidence: 0.70415837
<SIP/john-00000000>AGI Tx >> 510 Invalid or unknown command
<SIP/john-00000000>AGI Rx << EXEC Playback /path-to-sound-file/1
– AGI Script Executing Application: (Playback) Options: (/path-to-sound-file/1)
– <SIP/john-00000000> Playing ‘/path-to-sound-file/1.slin’ (language ‘en’)
[Jul 22 08:20:47] WARNING[2336]: db.c:332 ast_db_put: Couldn’t execute statment: SQL logic error
<SIP/john-00000000>AGI Tx >> 200 result=0
<SIP/john-00000000>AGI Rx << GET DATA beep 3000 2
– <SIP/john-00000000> Playing ‘beep.gsm’ (language ‘en’)
<SIP/john-00000000>AGI Rx << EXEC Playback /path-to-sound-file/no_key_press
– AGI Script Executing Application: (Playback) Options: (/path-to-sound-file/no_key_press)
– <SIP/john-00000000> Playing ‘/path-to-sound-file/no_key_press.slin’ (language ‘en’)
<SIP/john-00000000>AGI Tx >> 200 result=0
<SIP/john-00000000>AGI Rx << EXEC Playback /path-to-sound-file/1
– AGI Script Executing Application: (Playback) Options: (/path-to-sound-file/1)
– <SIP/john-00000000> Playing ‘/path-to-sound-file/1.slin’ (language ‘en’)
<SIP/john-00000000>AGI Tx >> 200 result=0
<SIP/john-00000000>AGI Rx << GET DATA beep 3000 2
<SIP/john-00000000>AGI Tx >> 511 Command Not Permitted on a dead channel or intercept routine
– <SIP/john-00000000>AGI Script /var/lib/asterisk/agi-bin/agifile.php completed, returning 4
== Spawn extension (phones, 888, 3) exited non-zero on ‘SIP/dav-00000000’Preformatted text

I guess this is from the inlcuded file that you didn’t include!

this “Transcript: number 2 number 2 test number 2” Yes.
But this " 510 Invalid or unknown command" is strange, is it trying to read 510 as a command?

It is trying to interpret “Transcript: number 2 number 2 test number 2” as a command.

The AGI protocol is a request/response protocol that uses STDOUT and STDIN.

You (your AGI library) write a request ('GET DATA beep 3000 2') to STDOUT and you read a response ('200 result=2 (timeout)') from STDIN. Lather, rinse, repeat.

When you write a ‘status’ message to STDOUT, you violate that protocol ('510 Invalid or unknown command').

You can use the '$agi->verbose()' command to write a message to the Asterisk console.

Or, you can use 'syslog()' to write a message to the system error log. For PHP, I use something like:

        syslog(LOG_ERR
                , 'File:' . __FILE__
                . ', Function:' . __FUNCTION__
                . ', Line:' . __LINE__
                . ' Yippie!'
                );

So to fix the problem, is it that I should capture all the messages that causes the “ 510 Invalid or unknown command” like the “ Transcript: number 2 number 2 test number 2” message in a variable `` highlighted by @ david551 above and put inside the verbose function like this:

After I use the message (in a variable) like put in database, then I put the variable in the verbose function like this:

$agi->verbose ($message, 4);``Preformatted text

This will fix THAT problem. I suspect there will be others :slight_smile:

thanks @sedwards and @david551 for information

To use 'Preformatted text' tags in a post (or reply) you can:

  1. Click on the ‘</>’ icon above the text box and type (or paste) over Preformatted text which is selected.

  2. Select a region of text and click on ‘</>.’

  3. Insert a ‘backtick’ before the region and after.

If you want to retain line breaks within the region, enter 3 backticks before and after.

I finally have it fixed without the verbose function, i just comment out the two php printf function in the script i put in the include function.
Thanks again @sedwards and @david551

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.