I am trying to inject audio into a local channel using the ChanSpy application, as opposed to using ConfBridge, for a number of reasons. I’ve not been able to get it working properly. What seems to be happening is that ChanSpy is only active when far end audio is detected on the channel. When there is audio from the called party, suddenly ChanSpy will work and I will hear the audio file, and as soon as far end audio goes silent again, so does ChanSpy. I’m trying to use ChanSpy to inject audio into the channel, with no regard to whether there is audio present there already or not.
I’ve tested this extensively for 6 hours on and off at this point, and this much is clear:
-
Changing the ChanSpy configuration does not seem to help. I have used the qw, qW, qWB, qB, qo, and even without the q, etc. options. No ChanSpy options make the application work properly -
The audio is playing... "somewhere". Not in the desired channel, except, of course, only during times when there is far end audio, and then I can hear it. The audio plays and loops as intended which I can see in the CLI, and during times when it is audible, it is nice and loud, and as soon as far end audio drops again, audio disappears. -
Calling party audio presence makes no difference. Only called party audio presence does. -
ChanSpy in general seems to work. I use ChanSpy for more "normal" applications and when I test trying to barge into a call, that seems to work. -
It does not have to do with what is being injected (that is, the properties of the audio file). -
Whether I connect ChanSpy to a local dialplan context or directly to a Playback using a call file, the result is the same. -
Adding an additional Local dial with the /n modifier does not help. (Usually, doing this tends to fix weird issues like this one) -
The actual channel name is something like Local/....;2. I tried spying on Local/....;1 instead (with everything else the same), and then there was never any audio audible at all. -
For testing purposes, even manually changing the spied on channel, for instance from the actual Local channel to the SIP peer that's way up the channel stack that spawned it, does not fix the issue. -
I tested it the other way, on incoming calls instead of outgoing calls, and the same issue persists.
It seems like something is broken somewhere, but I’ve been unable to find a workaround so far. Is this in any way expected behavior of the ChanSpy application? Is there anything I might change in my approach to make it work for my application? It’s unclear to me if this is a bug or deliberate behavior that could be removed by modified app_chanspy.c or something of the like. Is there some property of ChanSpy that makes it inactive if it doesn’t detect certain audio properties on the spied on channel? I looked at the source code but nothing stood out to me. I am using Asterisk 13.38.
There are multiple Stack Overflow questions asking how to do precisely this type of thing (inject audio into a channel), and multiple accepted answers recommend ChanSpy with qw or similar options, so I’m not alone in this approach and thus puzzled why it seems to be failing me.
More background: In theory, I could use a Confbridge, but if I did that, I would need to write all of the channel variables into global variables, then write them back into the call in the new outgoing leg, and then I would need to bring the actual outbound call into the bridge with the G option, fork the call upon answer, drop the called party into the bridge directly, kick the calling party out of the bridge, Answer() the call in the dialplan, and then drop the party back into the bridge (and even then, this only works because I have modified app_confbridge.c to not automatically supervise, or otherwise this would, in fact, not work at all since it would be impossible to provide accurate answer supervision). On top of that, when all this is done, it’s a confbridge, so the audio will never be as good as if the legs were directly connected to each other. Additionally, I have done similar things in the past, and it’s a high load and thus a very easy way to crash Asterisk and the server to the point where it requires a hard reboot. Since I’m only trying to put audio into the channel in one direction, ChanSpy seems like a far more sane, resource-friendly, and practical option (if I can get it to work).