Here is my solution
*I wrote it in AEL, much easier to understand
First I assume you got the callee number and file you want to play:
context Start
{
catch s {
Wait(1);
...
__NumberToDial=<Number that caller picked>;
FileName=<File you want to play>;
...
// I used SHARED variables to pass all the necessary data to sub channel
SHARED(FileName)=${FileName};
__Channel="${CHANNEL(name)}";
Dial(Local/${CALLERID(num)}@Originate/n,,g);
}
}
context Originate {
_X. => {
Originate(SIP/<YourDialOutTrunk>/${NumberToDial},exten,Play,${Channel},1);
if (${ORIGINATE_STATUS}!=SUCCESS)
{
//do stuff if not connected...
}
else
ChanSpy(,qsSg(${Channel}));
}
}
context Play {
_X. => {
Channel="${CUT(EXTEN,?,1)}";
Set(SPYGROUP=${Channel});
FileName=${SHARED(FileName,${Channel})};
Playback(${FileName});
}
}
*add w
option to ChanSpy if you want to allow whisper/talk
I didn't test this whisper!
You need to add catch => h everywhere and rest of the logic you need.
Whit this you will get the good timing. Only problem is to kill Originate channel if caller decide to hangup, which I've done sending channel kill on AMI with AGI script sending it channel name... bla bla... :)
Hope it helps :)