Record call using EAGI and Python

Hello everyone,

I’m currently working on a school project where I need to pass the audio stream from an asterisk call to an external script for analysis and kinda automate the call based on what is said during the call.

I made some researches and found that the audio stream can be accessed thanks to Asterisk EAGI but I can’t find any example or clear explanations on how to do it. I have already set up my Asterisk environment and I’m able to execute my python script as an EAGI script and do some basic operations.
This is what my EAGI script looks like right now :

import sys
*from asterisk.agi import **

agi = AGI()
agi.verbose(“Python AGI started successfully”)
callerId = agi.env[‘agi_callerid’]
agi.verbose(“Call from %s” % callerId)

I read that I need to use File Descriptor 3 to get the incoming audio stream and I would like to write the audio stream to an actual audio file on my computer. I would like to save the calls to train a model. The objective is to later have an EAGI script that records the call for like 10sec → analyze the audio → take a decision → record → etc.

And before I forget, I’m using the Pyst2 library.

So any help on how can I do this will be reallyd appreciated :slight_smile:
Thanks to anyone who will read this post !

Did you try the built-in Asterisk dial plan Record() application ?

That app would let you record to a file. Then in the next line of dial plan in your extensions.conf file, invoke your AGI() to process the recorded file. And in the line of dial plan after that, branch around to another context/extension/priority, based on the results of the AGI, using GosubIf(), GotoIf(), etc.

This lets you decouple the solution – separating between recording, processing, and branching – which may help you with testing and training of your model (sounds like that will be where most of your work is anyhow.)

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