Running Spychan when call is picked up instead of manually dialing in

Hi everyone.

I’m new to Asterisk and FreePbx and what I’m trying to do is to automatically listen into the call when it’s picked up/answered.

I found this code
https: //gist. github. com /lgaetz/78c4e114952e79596c1ed4123559d3d3
(sorry for link formating - this forum won’t let me create them in a post for some reason)
that does half of the work - the heavy lifting of actually listening to the call in the background. But it requires you to manually dial a number and the number of extension that is currently in a call in order to spy on it. Also, ending the ‘call’ sesion which was active requires a click.

Is there a way for this process to be automated?

Flow would be something along the lines of:

  1. Call to any valid custom extension comes in
  2. Call is answered
  3. [targeted-chanspy] context is fired up with the number of active call extension
  4. Call is completed and so is the spy session along with it

Thanks in advance

You missed a step, which is calling the extension that is going to listen in.

Hi David.

What exactly do you mean by ‘calling the extension that is going to listen in’?
I would like to run EAGI script in the background as soon as the call is answered so no actual listening of the conversation is performed.

Spy has to be run on a channel. The normal intent of that is a manager calls in on that channel. If you are automating, you will have to call the manager before setting up the spy request.

You would need to originate to local channel to run the script and also to the spy application.

In practice, you would need to run the originate either from an answer subroutine for the Dial (I’m not sure of the fine details of doing this on FreePBX), or by using AMI to monitor for the answer.

Thanks for answering David.

Do you know of any resources I could use to utilise AMI for this task? I’m talking articles, tutorials, etc.

Uhm, then why are you wanting to use ChanSpy? The whole point is for someone(s) to listen in on the call. What is the actual goal you’re trying to achieve here?

The ‘listening’ wil be performed by this library https ://github .com/andrewyang17/goEagi and the convo is to be sent to Google Speech to text API for transcription. I said listen as in context of having access to which I understand you need a third extension to join in to do so.
I want to know if I can somehow mimic that scenario automatically so I dont have to dial in manualy as I have to do with the code I linked to in the original post.

Why do you need to do this in near real time. In principle you would get a better transcription if you recorded the call and transcribed it after it finished. I’m not sure to what extent Google speech recognition looks ahead, or backtracks, but if it isn’t doing it much now, I imagine that the trend will be to do it in the near future.

IMO: This is the wrong approach. I’d use:


Asterisk External Application Protocol: Speech to Text Engine ⋆ Asterisk

If you actually end us getting it to work, please contribute back to the community by sharing the details

I achieve similar results with

(You will need working asterisk ‘headers’ to build the res_* modules )

Hi Dicko,

Thanks for answering. Vosk seems promising but I have issues installing it on my FPBX machine.

I’ve tried installing Vosk following steps in the repository you linked to but failed to do so. Error I’m having jumps out when i try ./configure step and it says Could not find asterisk.h, make sure Asterisk development package is installed

After some googling I tried running yum install asterisk18-devel and got nothing. Afterwards, I tried all of the steps from https:// wiki.freepbx .org/pages/viewpage.action?pageId=216175450.
Problem is there is an asterisk.h file in /usr/include directory after I went thru with all of the steps but the ./configure won’t pick it up.

./configure --with-asterisk=/usr/lib64/asterisk/modules --prefix=/usr

Do you happen to know what could be the issue here?


(You will need working asterisk ‘headers’ to build the res_* modules )

You would need to get them from whoever published the version of asterisk you use, or build your own asterisk.

Do you have any resources on how to use those headers when I obtain them to build modules?

If you compile asterisk from source , it will just ‘be there’, if you used a package manager , look for a matching dev or devel package too install.

Ok so I have installed devel package as I said using steps mentioned here and now I have asterisk.h file in /usr/include directory.
FreePBX is installed from ISO file downloaded from

What I’m guessing is wrong here is my ./configure command…
Example command form vosk github page says: ./configure --with-asterisk=<path_to_asterisk_source> --prefix=<path_to_install> but I’m not sure what path_to_asterisk_source and path_to_install would be after I installed devel package.

Do you maybe have any clue what could those paths be?

You need the asterisk dev/devel package not freepbx and asterisk.h not speech.h

Already installed that.
Nevermind guys over at vosk github page helped.

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