Please Help me, how to record during the Originate call?

Hello everyone, I have a problem. Please help me. Thank you very much!

Background:

  1. Asterisk 16
  2. Originate dials PSTN 13xxx, and dials local extension 888 after the call is connected

Problem:
If the voice speaker of 13xxx number is turned on, it will be automatically connected and call extension 888. When 888 answers, it is an invalid call.

Idea:

  1. During the call of 13xxx, I want to analyze the recording when calling, and use ASR to determine whether it is a voice mailbox. If so, the call will be terminated.

Attempt:

  1. Use MixMonitor and Monitor to record only after connecting 13xxx.
  2. During the call, the size of the recording file is always 44 bytes

Command:

CLI> channel originate local/130@dial-callback extension 888@dial-callback

Configuration:

[dial-callback]
exten=> 130,1,Set(CALLFILENAME=to-130-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
exten=> 130,n,MixMonitor(${CALLFILENAME}.wav)
exten=> 130,n,Dial(SIP/OneOut/13xxx)
exten=> 130,n,Hangup()

; Dial plan for extension 888
exten=> 888,1,Dial(SIP/888)
exten=> 888,n,Hangup()

Hi lanrenwo,

I’m not sure I completely follow your scenario, since I don’t understand “If the voice speaker of 13xxx number is turned on” means exactly. My initial thought was you had a SIP device with auto-answer enabled, but then it says you dialed PSTN so I don’t think that’s it.

If you’re ultimately trying to detect if 13xxx is answered by a machine/voicemail, have you looked at the AMD() function of Asterisk? I think that might be what you are needing.

You don’t need to listen/record during the Originate, you need to listen after the Dial to 130 is answered. Put the AMD() call in the exten => 888 before the Dial there. It will then listen to the connected call and determine whether it thinks it was answered by human or machine. Then either make the Dial to 888 or not based on the AMD() result using a ExecIf or something like that.

Regards,
Ron

Hi Ron,

Thank you for your response!

The 13xxx is a member’s phone number, and I use a third-party service OneOut (SIP TRUNK) to call him. Currently, I can only start recording after the call is connected, which corresponds to item 2 below. The audio during the call setup is not present in the recording file.

  1. Ring: You can hear “After the beep for voicemail, the charge starts. If you don’t want to leave a message, please hang up. Quick message. After the beep, please press the asterisk key.”
  2. Answered: You can hear “You have entered the voicemail of 13xxx. Please leave a message after the beep.”

If using AMD, it can only detect after the call is connected.

I tried adding Answer(), and the recording file then includes the above messages, but Originate will call both 13xxx and 888 simultaneously (I expect it to call 13xxx first, and after it’s connected, then call 888), so it’s not suitable for me.

Thanks again for your response!

[dial-callback]
exten => 130,1,Answer()
exten => 130,n,Set(CALLFILENAME=to-130-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
exten => 130,n,MixMonitor(${CALLFILENAME}.wav)
exten => 130,n,Dial(SIP/OneOut/13xxx)
exten => 130,n,Hangup()

; Dial plan for extension 888
exten => 888,1,Dial(SIP/888)
exten => 888,n,Hangup()

Regards,
Lanrenwo

I found some information that the 183 Session Progress returned from the SIP Trunk provider will have Early media. Currently, Asterisk cannot detect it before the answer.

The calls to 13XXX and 888 are not simultaneous, they just seem like it to you because you have no logic to control if/when the Dial(SIP/888) happens or not. Put a Wait(10) before the Dial(SIP/888) and you’ll see my point.

Personally, I’d do this using ARI with a snoop channel or external media channel to pipe the audio to whatever I was using to do the analysis rather than record to file first. Recording to a file first won’t let you do it in real-time well. Especially not using a .wav format.

If you are going to use a file recording, I’d suggest a different format than .wav. .wav files have a wrapper around the actual data that contains info about the data inside the file (so Windows could understand it). You only want the data within it anyway if you are trying to analyze it in real-time.

I also think to do this in dialplan, you’d need to move your MixMonitor() call to the 888 side of the call and put your logic between that and your Dial() as to whether you actually execute the Dial(SIP/888). The MixMonitor() would need to be proceeded with a Progress() I believe to get the audio path established first to record Early Media. I can’t say this would work for sure as I’ve never tried this in dialplan, but it is what I’d try if I was insisting on going it in dialplan. You may have to put a StopMixMonitor() in there to get the file to write out for sure before you will get data written to the file. There are much better ways to do this.

You should also be using PJSIP, rather than SIP. SIP is going away.

Regards,
Ron

Hi Ron,

Firstly, thank you for your response and suggestions.

Currently, my plan is also similar to the wait solution, but it processes through AGI, monitoring the recording files. The development is complete and we’re preparing for deployment.

Regarding the mentioned solution of monitoring channels to obtain recordings, I haven’t found a solution yet, so I will conduct further research, including on PSIP.
Once again, thank you for your response and suggestions!

Regards,
Lanrenwo

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