You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Asterisk中如何实现按#键中断Monitor()命令的音频录制?

How to Stop Asterisk's Monitor() with DTMF # Key

Great question! Unlike Record(), Asterisk's Monitor() command doesn’t have a built-in parameter to stop recording when a DTMF key is pressed. But we can add this functionality with straightforward dialplan logic—here’s how to implement it:

Core Approach

We’ll start the Monitor() process, then listen for DTMF input using WaitExten() (or Background() if you need to play audio prompts). When the # key is detected, we’ll trigger StopMonitor() to halt the recording immediately.

Dialplan Example

Here’s a complete, tested dialplan snippet you can adapt:

[monitor-with-dtmf-stop]
exten => s,1,NoOp(Initiating call recording with # stop trigger)
; Start monitoring - adjust format (wav/gsm), filename, and options as needed
; The "mb" option mixes both caller and callee audio into a single file (optional)
exten => s,n,Monitor(wav,call_recording_${UNIQUEID},mb)
; Listen for DTMF input for 3600 seconds (1 hour) - use 0 for infinite wait
exten => s,n,WaitExten(3600)

; Handle the # DTMF key press
exten => #,1,NoOp(# key detected - stopping recording)
exten => #,n,StopMonitor()
; Optional: Add logic here to continue the call or hang up
exten => #,n,Hangup()

; Handle timeout (no DTMF pressed within the wait period)
exten => t,1,NoOp(Timeout reached - stopping recording)
exten => t,n,StopMonitor()
exten => t,n,Hangup()

Key Details & Customizations

  • Dynamic Filenames: Using ${UNIQUEID} ensures each call gets a unique recording filename, avoiding overwrites.
  • DTMF Detection: Ensure your channel configuration (e.g., sip.conf for SIP trunks) has the correct dtmfmode set (common values are rfc2833 or info).
  • Playing Prompts: If you need to play an audio prompt while monitoring (e.g., "Press # to stop recording"), replace WaitExten(3600) with Background(your_prompt_file)—the # extension will still trigger when pressed.
  • Infinite Wait: Use WaitExten(0) instead of 3600 if you want to listen for DTMF until the call ends or the # key is pressed.

Troubleshooting Tip

If DTMF isn’t triggering the # extension, check Asterisk’s logs (/var/log/asterisk/full) to confirm DTMF events are being detected. You can also add Verbose(3) in the dialplan to debug DTMF input in real-time.

内容的提问来源于stack exchange,提问作者eran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:02:55