Calling php file from php file

Hi all,
i am new to Asterisk and AGI scripting and really need help to accomplish my task.

I ran a “Globalmenu.php” script which is working fine with speech recognition. when “banking” word is recognized by Automatic Speech Recognition, script is calling the submenu.php, but from there on, speech recognition is not happening like it happened normally when submenu.php is executed individually.

here is the code for Globalmenu.php

#!/usr/bin/php -q

<?php require('phpagi.php'); error_reporting(E_ALL); $agi = new AGI(); $tries=0; $globalmenuopt; $agi->exec('SpeechCreate'); $agi->exec('SET','SPEECH_RESULTS_TYPE()=nbest'); $agi->exec('SpeechLoadGrammar globalmenu,/var/lib/asterisk/agi-bin/globalmenu'); $globalmenuopt=mainmenu($agi); function mainmenu($agi){ global $globalmenuopt; list($globalmenuopt,$globalmenuoptscore)=collectInput($agi,"globalmenu","bankingdemo/GlobalMenu"); if($globalmenuopt==""){ global $tries; $tries++; $agi->verbose("tries: $tries"); if($tries>=3){ $agi->hangup(); } $globalmenuopt=mainmenu($agi); return $globalmenuopt; } return $globalmenuopt; } if($globalmenuopt=="Banking"){ include('/var/lib/asterisk/agi-bin/submenu.php'); } function collectInput($agi,$grammarfile,$prompt) { $agi->exec('SpeechActivateGrammar '.$grammarfile); $agi->exec('SpeechStart'); $recogoutput=$agi->exec('SpeechBackground '.$prompt.',8'); $score=$agi->get_variable('SPEECH_SCORE(0)'); $text=$agi->get_variable('SPEECH_TEXT(0)'); $agi->verbose("$grammarfile score: ".$score['data']); $agi->verbose("$grammarfile word: ".$text['data']); $agi->exec('SpeechDeactivateGrammar'); $result=$text['data']; $weight=$score['data']; return array($result,$weight); } ?>

AND
here is submenu.php code

#!/usr/bin/php -q

<?php require('phpagi.php'); error_reporting(E_ALL); #$agi = new AGI(); $tries=0; $submenuopt; $agi->exec('SpeechCreate'); $agi->exec('SET','SPEECH_RESULTS_TYPE()=nbest'); $agi->exec('SpeechLoadGrammar submenu,/var/lib/asterisk/agi-bin/submenu'); $submenuopt=banksubmenu($agi); function banksubmenu($agi){ global $submenuopt; list($submenuopt,$submenuoptscore)=collectInput($agi,"submenu","bankingdemo/subMenu"); if($submenuopt==""){ global $tries; $tries++; $agi->verbose("tries: $tries"); if($tries>=3){ $agi->hangup(); } $submenuopt=banksubmenu($agi); return $submenuopt; } return $submenuopt; } if($submenuopt=="account"){ $agi->stream_file('bankingdemo/Play'); } function collectInput($agi,$grammarfile,$prompt) { $agi->exec('SpeechActivateGrammar '.$grammarfile); $agi->exec('SpeechStart'); $recogoutput=$agi->exec('SpeechBackground '.$prompt.',8'); $score=$agi->get_variable('SPEECH_SCORE(0)'); $text=$agi->get_variable('SPEECH_TEXT(0)'); $agi->verbose("$grammarfile score: ".$score['data']); $agi->verbose("$grammarfile word: ".$text['data']); $agi->exec('SpeechDeactivateGrammar'); $result=$text['data']; $weight=$score['data']; return array($result,$weight); } ?>

not sure any of the developers ever had to face any issue in similar lines. I appreciate any insight from the gurus. Thankyou for your time

Regards,

Just a WAG as I shun PHP in Asterisk - the line
#$agi = new AGI();
is breaking the AGI protocol so you’re losing the connection to your speech engine - AGI is pretty forgiving until it needs to “slap your knuckles”.

yes, it seems i am losing connection to speech system in the process of calling another PhP. The recognition fails although the second php file that i call is being executed. any thoughts on how to hold the speech engine while maneuvering from script to script?

As I said, PHP is my “third cousin thrice removed” - but I think the solution to your problem is to do the speech engine interaction from a “single source” that calls the other modules. Asterisk (as I know it) is for the most part a single-thread program. Trying to carry functionality across 2 or 3 threads outside of the main program is not (IMHO) a good idea.