Giter Site home page Giter Site logo

damded / freeswitch-chatbot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wkyo/freeswitch-chatbot

0.0 0.0 0.0 24 KB

FreeSWITCH、ASR、TTS以及文本聊天机器人简易集成

License: GNU General Public License v3.0

Shell 14.40% Python 85.60%

freeswitch-chatbot's Introduction

FreeSWITCH Chatbot

FreeSWITCH、ASR、TTS以及文本聊天机器人简易集成

Environment

  • Debian 9 Stretch
  • FreeSWITCH 1.8
  • ASR: UniMRCP (modified by Baidu)
  • TTS: Baidu TTS (Web API)
  • Robot: echobot (wrapper)
  • Python2 (limited by FreeSWITCH): python-dev python-requests

TODO

  • Refactor (Plugin Support)

FreeSWITCH 部署

安装

为了简化部署,我们直接为APT (Debian) 添加FreeSWITCH软件源。

wget -O - https://files.freeswitch.org/repo/deb/freeswitch-1.8/fsstretch-archive-keyring.asc | apt-key add -
echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.8/ stretch main" > /etc/apt/sources.list.d/freeswitch.list
echo "deb-src http://files.freeswitch.org/repo/deb/freeswitch-1.8/ stretch main" >> /etc/apt/sources.list.d/freeswitch.list
apt-get update && apt-get install -y freeswitch-meta-all

最后启动服务systemctl start freeswitch,使用fs_cli -rRS访问控制台。如果当前电脑上没有ipv6地址,这里将会出现[ERROR] fs_cli.c:1673 main() Error Connecting []错误,修改配置文件/etc/freeswitch/autoload_configs/event_socket.conf.xml中的listen-ip

<configuration name="event_socket.conf" description="Socket Client">   
  <settings> 
    <param name="nat-map" value="false"/>
    <param name="listen-ip" value="127.0.0.1"/>
    <param name="listen-port" value="8021"/>
    <param name="password" value="ClueCon"/>
    <!--<param name="apply-inbound-acl" value="loopback.auto"/>-->
    <!--<param name="stop-on-bind-error" value="true"/>-->
  </settings>
</configuration>

配置

修改默认密码

编辑/etc/freeswitch/vars.xml,修改默认密码1234

<include>
  <X-PRE-PROCESS cmd="set" data="default_password=dev1234"/>
  <!-- ... others ... -->
</include>

启用Python及UniMRCP支持

编辑/etc/freeswitch/autoload_configs/modules.conf.xml,添加mod_pythonmod_unimrcp启用Python及UniMRCP模块。

  • mod_python模块对外提供FreeSWITCH的Python2接口。
  • mod_unimrcp模块集成了UniMRCP客户端接口,简单配置后就可以直接使用FreeSWITCH的标准接口通过UniMRCP服务器进行语音识别与语音合成。
<configuration name="modules.conf" description="Modules">
  <modules>
    <!-- ... others ... -->
    <load module="mod_python" />
    <load module="mod_unimrcp" />
  </modules>
</configuration>

配置UniMRCP

具体配置请查阅 UniMRCP mod_unimrcp 文档

FreeSWITCH没有为UniMRCP服务器提供MRCPv2协议的配置文件,需要在/etc/freeswitch/mrcp_profiles下新建文件unimrcpserver-mrcp-v2.xml。由于我们将FreeSWITC与UniMRCP服务器部署在同一台服务器上,这里server-ip127.0.0.1

<!-- unimrcpserver-mrcp-v2.xml -->
<include>
  <!-- UniMRCP Server MRCPv2 -->
  <profile name="unimrcpserver-mrcp2" version="2">
    <param name="server-ip" value="127.0.0.1"/>
    <param name="server-port" value="8060"/>
    <param name="resource-location" value=""/>
    <param name="client-ip" value="auto" />
    <param name="client-port" value="5069"/>
    <param name="sip-transport" value="udp"/>
    <param name="rtp-ip" value="auto"/>
    <param name="rtp-port-min" value="4000"/>
    <param name="rtp-port-max" value="5000"/>
    <param name="codecs" value="PCMU PCMA L16/96/8000"/>
    <param name="speechsynth" value="speechsynthesizer"/>
    <param name="speechrecog" value="speechrecognizer"/>
  </profile>
</include>

配置文件unimrcpserver-mrcp-v2.xml中的speechsynthspeechrecog的值可以在UniMRCP服务器的配置文件unimrcpserver.xml中找到。

<!-- unimrcpserver.xml -->
<unimrcpserver>
  <components>
    <rtsp-uas id="RTSP-Agent-1" type="UniRTSP">
      <resource-map>
        <param name="speechsynth" value="speechsynthesizer"/>
        <param name="speechrecog" value="speechrecognizer"/>
      </resource-map>
    </rtsp-uas>
  </components>
</unimrcpserver>

最后修改/etc/freeswitch/autoload_configs/unimrcp.conf.xmldefault-tts-profiledefault-asr-profile的值为我们之前添加的MRCPv2配置文件的名称unimrcpserver-mrcp2

<configuration name="unimrcp.conf" description="UniMRCP Client">
  <settings>
    <!-- UniMRCP profile to use for TTS -->
    <param name="default-tts-profile" value="unimrcpserver-mrcp2"/>
    <!-- UniMRCP profile to use for ASR -->
    <param name="default-asr-profile" value="unimrcpserver-mrcp2"/>
    <!-- UniMRCP logging level to appear in freeswitch.log.  Options are:
         EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG -->
    <param name="log-level" value="DEBUG"/>
    <!-- Enable events for profile creation, open, and close -->
    <param name="enable-profile-events" value="false"/>

    <param name="max-connection-count" value="100"/>
    <param name="offer-new-connection" value="1"/>
    <param name="request-timeout" value="3000"/>
  </settings>

  <profiles>
    <X-PRE-PROCESS cmd="include" data="../mrcp_profiles/*.xml"/>
  </profiles>

</configuration>

FAQ

FreeSWITCH 呼叫接入慢

网上的大多数方法是修改 /etc/freeswitch/dialplan/default.xmlfield="${default_password}" 规则下的休眠时间,但只有默认密码为1234时,该规则才会被触发。在前面我们已经修改了默认的密码,这里修改该规则将没有任何作用。

<condition field="${default_password}" expression="^1234$" break="never">
<action application="log" data="CRIT WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING "/>
<action application="log" data="CRIT Open $${conf_dir}/vars.xml and change the default_password."/>
<action application="log" data="CRIT Once changed type 'reloadxml' at the console."/>
<action application="log" data="CRIT WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING "/>
<action application="sleep" data="10000"/>
</condition>

在公网环境中,由于存在大量恶意SIP访问,FS资源被占用,新的呼叫将会进行长时等待。在低配服务器上,这种情况更加严重,等待时长可能高达30s+。为了减轻服务器负担,这里可以使用ipsetiptables命令配合屏蔽掉大量恶意IP。

# 创建集合blacksip并添加ip
ipset create blacksip hash:net family inet hashsize 1024 maxelem 1000000
ipset add blacksip 36.66.69.33
ipset add blacksip ...other bad ip...
# 这里直接拒绝来自blacksip集合内ip的所有访问途径
iptables -I INPUT -m set --match-set blacksip src -j DROP

这里,我提供了一个精简的IP屏蔽列表 blackip/blacksip.ipset,实际使用中发现大部分的恶意IP都是来自于荷兰,或许可以把整个荷兰的IP都给ban掉。这里也可从仓库firehol/blocklist-ipsets获取公开的恶意IP列表。

FreeSWITCH Chatbot 集成

EASY !!!

chatbot/fs2chatbot.py 提供了FreeSWITCH与外部的交互接口。

TODO...

freeswitch-chatbot's People

Contributors

wkyo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.