Channel out heard in channel in from phpagi

I’m recording channel in and out while playing a sound file on channel out.
In extensions.conf works perfectly well as I do not hear channel out in channel in.

exten => s,n,Monitor(gsm,voicecapture)
exten => s,n,backgrounddetect(menufile)
exten => s,n,StopMonitor

Same thing from a php script launched from extensions.conf I do hear channel out

exten => 112,1,Answer
exten => 112,2,AGI(test2.php)

and test2.php is:
#!/usr/bin/php -q

<?php set_time_limit(0); require_once('phpagi.php'); $agi= new AGI(); $agi->answer(); $agi->exec("Monitor","gsm,test"); $agi->exec("BackgroundDetect", "$menufile"); $agi->exec("StopMonitor"); $agi->hangup()

It is impossible to perfectly cancel echos in the real world.

Running on a virtual machine is not advisable, but unlikely to be the problem here. If you have to run on a VM, make sure that it is configured to give scheduling latencies of less than 20ms and reserve enough CPU and memory that the VM is not wanting for either.

[quote=“david55”]It is impossible to perfectly cancel echos in the real world.

Running on a virtual machine is not advisable, but unlikely to be the problem here. If you have to run on a VM, make sure that it is configured to give scheduling latencies of less than 20ms and reserve enough CPU and memory that the VM is not wanting for either.[/quote]

thanks a lot dave.
After playing with the recorded files, I figured out that after I say something on channel in then recorded audio level from channel out into channel in drops dramatically. Thinking that asterisk might need to listen a bit to environment to adjust audio level before working I decided to add 2 seconds of silence at the beginning of the outgoing message and now it seems to work. This is probably not a good solution so I will also investigate what you’ve suggested.

Well as expected a bad fix is not a long term solution so it does not work now.
dave55, would latency explain why it works in the dialplan and a lot less in a phpscript? Also a ping between the virtual machine to the ip address of the windows pc on which xlite is installed is less than 10ms, generally less that 2ms (By the way the VM is installed on the same pc but has its own ip address)
Thank you

Latency will give poor audio quality. As already noted, it probably wouldn’t cause your particular problems.

Finally resolved it and I really feel stupid. So other people don’t waste a week as I did: don’t forget to SHUT DOWN THE MICROPHONE of the virtual machine (but not on the host).
Note to self: Think a little harder