freeswitch檢測信號音,包括回鈴音、忙音、故障音

最近項目有相關回鈴音檢測需要,網上找了一圈,各種信息參差不齊,最後也算弄成了。這裏直接給出實操教程。

用到的模塊是mod_spandsp,默認編譯時會預裝的,之前檢測DTMF的文章裏也有用到這個模塊。

conf/autoload_configs/spandsp.conf.xml的descriptors節點下面增加中國信號音的相關配置

<!-- China -->
    <descriptor name="cn">
        <tone name="標準回鈴音">
            <element freq1="450" freq2="0" min="900" max="1100"/>
            <element freq1="0" freq2="0" min="900" max="4100"/>
	    <element freq1="450" freq2="0" min="900" max="1100"/>
            <element freq1="0" freq2="0" min="900" max="4100"/>
        </tone>
        <tone name="標準忙音1">
            <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>
	<tone name="標準忙音2">
            <element freq1="450" freq2="0" min="300" max="400"/>
            <element freq1="0" freq2="0" min="250" max="350"/>
            <element freq1="450" freq2="0" min="300" max="400"/>
            <element freq1="0" freq2="0" min="250" max="350"/>
            <element freq1="450" freq2="0" min="300" max="400"/>
            <element freq1="0" freq2="0" min="250" max="350"/>
         </tone>
	<tone name="三短一長錯誤音">
            <element freq1="450" freq2="0" min="50" max="150"/>
            <element freq1="0" freq2="0" min="50" max="150"/>
            <element freq1="450" freq2="0" min="50" max="150"/>
            <element freq1="0" freq2="0" min="50" max="150"/>
            <element freq1="450" freq2="0" min="50" max="150"/>
            <element freq1="0" freq2="0" min="50" max="150"/>
            <element freq1="450" freq2="0" min="300" max="500"/>
            <element freq1="0" freq2="0" min="300" max="500"/>
         </tone>
    </descriptor>

 

450是中國信號音頻率,min和 max 和持續時間的最小和最大,可根據實際情況增加更多的順序,最後一定要以靜音結束,不然會一直循環報告信號事件

PS:descriptors節點名後面加上 debug-level="2" 可開啓信號音檢測詳情,可根據詳情調整或新增新情況

一般收到媒體事件(CHANNEL_PROGRESS_MEDIA)時,就可以開啓檢測了

API方式: spandsp_start_tone_detect uuid cn 

diaplan方式:bridge裏面增加前置參數 {execute_on_media=spandsp_start_tone_detect cn}

 

一般通道應答後,就可以關掉了,節省資源

API方式:spandsp_stop_tone_detect uuid 

diaplan方式:bridge裏面增加前置參數{execute_on_answer=spandsp_stop_tone_detect}

當檢測到設置的各種tone時,控制檯下會輸出

DETECTED TONE: TONE_NAME

TONE_NAME就是配置裏面相應的NAME(標準回鈴音、標準忙音1等等)

相應的產生DETECTED_TONE事件,裏面的Detected-Tone變量值就是TONE_NAME

愉快的去玩耍吧。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章