FreeSWITCH信号音检测(忙音检测,呼叫进度检测)

FreeSWTICH有2种信号音检测方法一种mod_dptools: tone_detect,还有一个是mod_spandsp Call Progress,我们先介绍第一种。

如果需要可以识别出 彩铃,空号,关机,停机,彩铃,通话中,语音信箱,语音留言,等可以使用顶顶通开发的FreeSWITCH mod_da2模块,详细请看http://www.ddrj.com/asr/mod_da2.html

mod_dptools tone_detect

<action application="tone_detect" data="<key> <freqs> <flags> <timeout> <app> <data> <hits>">
Field Decription examples
key Name of the tone (user defined) busy, fax, mytone
freqs Frequencies to “listen” for 425 - 480,620
flags Which direction to sniff the tones in (r = read (default), w = write) r
timeout Window of time to listen for the tones in (0 = forever, + = milliseconds relative to the time tone_detect is called (now), = time in “epoch” (ie. seconds since January 1, 1970)) +2000 (2 seconds) or 1227132612 (absolute example)
app Optional. Application to call when the tone detect conditions are met transfer, hangup
appdata Optional. Argument to the application specified above ‘1000 XML default’ , ‘normal_clearing’
hits Number of hits needed before calling app/appdata (useful to avoid false positives)
  • timeout这里特别解析一下,0:一直检测,+毫秒数:需要检测的时间, epoch:绝对时间,比如要检测60秒,就是now()+60

  • freqs 中国电话信号音标准

    • 拨号音 450±25 -10±3dBm0 <10% 连续信号音
    • 回铃音 450±25 -10±3dBm0 <10% 1S(H)/4S(L)
    • 忙音 450±25 -10±3dBm0 <10% 0.35S(H)/0.35S(L)
    • 拥塞音 450±25 -10±3dBm0 <10% 0.7S(H)/0.7S(L)

如果上面表格中解析看不明白,没事,下面有例子。

<!-- execute_on_tone_detect 检测到信号音执行的操作 -->
<action application="set" data="execute_on_tone_detect=set my_tone=true"/>
<!-- tone_detect_hits 信号出现多少次才认为检测成功,比如忙音检测一般设置为3 -->
<action application="set" data="tone_detect_hits=2"/>
<action application="set" data="execute_on_media=tone_detect mytone 820 w +30000"/>
<action application="bridge" data="sofia/gateway/foo/123456789"/>

下面是一个检测到3声忙音就挂断的例子。

<action application="tone_detect" data="busy 450 r 0 hangup 'normal_clearing' 3"/>

停止信号音检测

<application="stop_tone_detect"/>

mod_spandsp Call Progress

mod_dptools: tone_detect功能比较弱,现在我们介绍第二种吧

<configuration name="spandsp.conf" description="Tone detector descriptors">
<descriptors debug-level="0">
<!-- These tones are defined in Annex to ITU Operational Bulletin No. 781 - 1.II.2003 -->
<!-- Various Tones Used in National Networks (According to ITU-T Recommendation E.180)(03/1998) -->
<!-- North America -->
<!-- china -->
<descriptor name="cn">
<tone name="BUSY_TONE">
<element freq1="450" freq2="0" min="300" max="400"/>
<element freq1="0" freq2="0" min="300" max="400"/>
<element freq1="450" freq2="0" min="300" max="400"/>
<element freq1="0" freq2="0" min="300" max="400"/>
<element freq1="450" freq2="0" min="300" max="400"/>
<element freq1="0" freq2="0" min="300" max="400"/>
</tone>
</descriptor>
</descriptors>
</configuration>

通过配置文件可以配置不同信号因频率、持续时间和周期。上面的配置是配置中国忙音,持续3声认为检测成功。

Channels Variables

  • execute_on_spandsp_tone_detect_XXX 检测到信号执行APP
  • api_on_spandsp_tone_detect_XXX 检测到信号执行API

Dialplan Applications

spandsp_start_tone_detect

Start background tone detection with cadence.

<!-- start detection for North American call progress tones -->
<action application="spandsp_start_tone_detect" data="1"/>

spandsp_stop_tone_detect

Stop background tone detection with cadence

<action application="spandsp_stop_tone_detect"/>

APIs

spandsp_start_tone_detect

Start background tone detection with cadence

spandsp_start_tone_detect <uuid> <descriptor name>

spandsp_stop_tone_detect

Stop background tone detection with cadence

spandsp_stop_tone_detect <uuid>

Events

DETECTED_TONE

This event is fired when the tone detector detects a tone.

The following headers are set:

Detected-Tone

Unique-ID

The Detected-Tone header will contain the name of the tone, as specified in the configuration file.

The Unique-ID will contain the session UUID.