|
這是我的第一個(gè)Github工程,特別感謝 Cotin網(wǎng)站 《構(gòu)建簡(jiǎn)單的智能客服系統(tǒng)》(一)、 (二) 、(三) 對(duì)于構(gòu)建過(guò)程的幫助,您在閱讀本教程前,可以先行閱讀這三篇文章,本教程基于此調(diào)整了構(gòu)建順序,給出更多的操作細(xì)節(jié),錯(cuò)誤處理以及其它構(gòu)建描述。 主要目的使用FreeSWITCH接受用戶手機(jī)呼叫,通過(guò)UniMRCP Server集成訊飛開(kāi)放平臺(tái)(xfyun)插件將用戶語(yǔ)音進(jìn)行語(yǔ)音識(shí)別(ASR),并根據(jù)自定義業(yè)務(wù)邏輯調(diào)用語(yǔ)音合成(TTS),構(gòu)建簡(jiǎn)單的端到端語(yǔ)音呼叫中心。 總體結(jié)構(gòu)如下圖所示:構(gòu)建步驟第一步 安裝編譯FreeSWITCH本次示例的FreeSWITCH在MacOS High Sierra 10.13.4系統(tǒng)版本中進(jìn)行源碼編譯安裝,未使用軟件包安裝,具體安裝步驟可見(jiàn) 官網(wǎng)安裝介紹 ,其他平臺(tái)如Linux(Ubuntu、CentOS)應(yīng)均能安裝成功。 以下給出源碼編譯安裝的步驟: 1.下載 FreeSWITCH源碼: cd /usr/local/src
git clone -b v1.6 https:///stash/scm/fs/freeswitch.git freeswitch2.安裝依賴庫(kù) brew install autoconf brew install automake brew install libtool brew install pkg-config brew install speexdsp brew install speex brew install libldns-dev brew install OpenSSL brew install pcre brew install pkgconfig sqlite3 brew intall lua brew install opus brew install libsndfile
3.編譯安裝 cd freeswitch/
./configure
make
make install
make cd-sounds-install
make cd-moh-install4.運(yùn)行 cd /usr/local/freeswitch/bin
./freeswitch即可啟動(dòng)應(yīng)用。
FreeSWITCH默認(rèn)配置1000-1019(20個(gè))用戶,默認(rèn)密碼1234,您可以提前跳轉(zhuǎn)到“第四步 測(cè)試與驗(yàn)證” 的驗(yàn)證步驟,登錄并撥打5000,可以聽(tīng)到默認(rèn)IVR的示例語(yǔ)音菜單指引。 第二步 配置編譯UniMRCP Server本次示例的UniMRCP Server在CentOS 7中進(jìn)行源碼編譯安裝,感謝由Github用戶cotinyang提供的已經(jīng)寫(xiě)好的集成訊飛SDK的UniMRCP Server源碼。 1.下載 UniMRCP Server Plugin Demo 源碼: cd /opt
git clone https://github.com/cotinyang/MRCP-Plugin-Demo.git MRCP-Plugin-Demo2.編譯準(zhǔn)備環(huán)境 cd MRCP-Plugin-Demo/unimrcp-deps-1.5.0
./build-dep-libs.sh
3.編譯安裝unimrcp cd unimrcp-1.5.0
./bootstrap
./configure
make
make install即可在/usr/local/中看到安裝好的unimrcp。 4.測(cè)試運(yùn)行 cd /usr/local/unimrcp/bin
./unimrcpserver -o 3可以使用client進(jìn)行驗(yàn)證 cd /usr/local/unimrcp/bin ./unimrcpclient >help usage: - run [app_name] [profile_name] (run demo application) app_name is one of 'synth', 'recog', 'bypass', 'discover' profile_name is one of 'uni2', 'uni1', ... examples: run synth run recog run synth uni1 run recog uni1 - loglevel [level] (set loglevel, one of 0,1...7) - quit, exit 輸入help回車,給出了使用方法,輸入run recog運(yùn)行語(yǔ)音識(shí)別測(cè)試,run synth進(jìn)行語(yǔ)音合成測(cè)試。 第三步 集成訊飛開(kāi)放平臺(tái)SDK1.訊飛開(kāi)發(fā)平臺(tái)SDK下載 由于從訊飛開(kāi)放平臺(tái)下載的SDK包和用戶以及用戶創(chuàng)建的應(yīng)用相關(guān)聯(lián),因此需要將third-party/xfyun中的文件和文件夾全部刪除,重新下載解壓屬于自己的SDK,目錄與源代碼基本一致。 您需要注冊(cè)并登錄 訊飛開(kāi)放平臺(tái) ,進(jìn)入控制臺(tái)頁(yè)面,并創(chuàng)建應(yīng)用; 在“我的應(yīng)用”界面獲得你的APPID,并為該應(yīng)用“添加新服務(wù)”,選擇需要的“語(yǔ)音聽(tīng)寫(xiě)”和”在線語(yǔ)音合成“服務(wù)(本示例需要); 點(diǎn)擊右側(cè)“SDK下載”,在跳轉(zhuǎn)頁(yè)面中確認(rèn)“選擇應(yīng)用”已經(jīng)選中了您創(chuàng)建的應(yīng)用,“選擇您需要的AI能力”選中上述兩項(xiàng)服務(wù),并點(diǎn)擊“SDK下載”等待SDK生成與完成下載。 將下載的zip包,解壓并替換MRCP-Plugin-Demo/unimrcp-1.5.0/plugins/third-party/xfyun/下的所有文件及文件夾。
2.plugin編寫(xiě)與編譯 本步驟將告訴您如何編寫(xiě)unimrcp的插件代碼,即現(xiàn)在MRCP-Plugin-Demo/unimrcp-1.5.0/plugins文件夾下xfyun_recog、xfyun_xynth文件夾下的文件及其相關(guān)配置是如何得到的,如果您當(dāng)前還不關(guān)注此細(xì)節(jié),可以跳過(guò)本步驟至第四步。 實(shí)際上,上述MRCP-Plugin-Demo代碼是在 Unimrcp官網(wǎng) 下載 Unimrcp 1.5.0 和 Unimrcp Deps 1.5.0 并在此基礎(chǔ)上添加的plugin代碼。 首先編輯configure.ac文件,會(huì)在后面的Makefile中使用到的宏定義。XFyun recognizer plugin的添加如下: dnl XFyun recognizer plugin. UNI_PLUGIN_ENABLED(xfyunrecog) AM_CONDITIONAL([XFYUNRECOG_PLUGIN],[test "${enable_xfyunrecog_plugin}" = "yes"]) ... plugins/xfyun-recog/Makefile ... echo XFyun recognizer plugin....... : $enable_xfyunrecog_plugin
對(duì)應(yīng)地,XFyun synthesizer plugin的添加如下: dnl XFyun synthesizer plugin. UNI_PLUGIN_ENABLED(xfyunsynth) AM_CONDITIONAL([XFYUNSYNTH_PLUGIN],[test "${enable_xfyunsynth_plugin}" = "yes"]) ··· plugins/xfyun-synth/Makefile ··· echo XFyun synthesizer plugin...... : $enable_xfyunsynth_plugin 新增源碼與目錄 在 plugins 目錄下,新建 xfyun-recog 目錄,并在該目錄下新建 src 目錄,可以將 demo_recog_engine.c 拷貝到該目錄下改名為 xfyun_recog_engine.c,將xfyun_recog_engine.c文件進(jìn)行修改(修改過(guò)程暫略),xfyun-synth目錄下對(duì)應(yīng)創(chuàng)建并修改。 在xfyun-recog文件夾下新建Makefile.am文件,內(nèi)容如下: AM_CPPFLAGS = $(UNIMRCP_PLUGIN_INCLUDES) plugin_LTLIBRARIES = xfyunrecog.la xfyunrecog_la_SOURCES = src/xfyun_recog_engine.c xfyunrecog_la_LDFLAGS = $(UNIMRCP_PLUGIN_OPTS) -L$(top_srcdir)/plugins/third-party/xfyun/libs/x64 -lmsc -ldl -lpthread -lrt xfyunrecog_ladir = $(libdir) xfyunrecog_la_DATA = $(top_srcdir)/plugins/third-party/xfyun/libs/x64/libmsc.so include $(top_srcdir)/build/rules/uniplugin.am UNIMRCP_PLUGIN_INCLUDES += -I$(top_srcdir)/plugins/third-party/xfyun/include 對(duì)應(yīng)地,在fyun-synth文件夾下新建Makefile.am文件夾,內(nèi)容如下: AM_CPPFLAGS = $(UNIMRCP_PLUGIN_INCLUDES) plugin_LTLIBRARIES = xfyunsynth.la xfyunsynth_la_SOURCES = src/xfyun_synth_engine.c xfyunsynth_la_LDFLAGS = $(UNIMRCP_PLUGIN_OPTS) -L$(top_srcdir)/plugins/third-party/xfyun/libs/x64 -lmsc -ldl -lpthread -lrt xfyunsynth_ladir = $(libdir) include $(top_srcdir)/build/rules/uniplugin.am UNIMRCP_PLUGIN_INCLUDES += -I$(top_srcdir)/plugins/third-party/xfyun/include 修改plugins文件夾下Makefile.am文件,xfyun-recog添加內(nèi)容如下: if XFYUNRECOG_PLUGIN
SUBDIRS += xfyun-recog
endif對(duì)應(yīng)地,xfyun-synth添加內(nèi)容如下: if XFYUNRECOG_PLUGIN
SUBDIRS += xfyun-synth
endif修改conf/unimrcpserver.xml文件,從默認(rèn)啟用demo engine改為啟用我們的兩個(gè)engine。 xfyun-recog修改如下: <engine id="Demo-Recog-1" name="demorecog" enable="false"/> <engine id="XFyun-Recog-1" name="xfyunrecog" enable="true"/> 對(duì)應(yīng)地,xfyun-synth修改如下: <engine id="Demo-Synth-1" name="demorecog" enable="false"/> <engine id="XFyun-Recog-1" name="xfyunrecog" enable="true"/> 同時(shí),如果您已經(jīng)準(zhǔn)備好將UniMRCP Server和FreeSWITCH對(duì)接,您應(yīng)該在conf/unimrcpserver.xml中配置好server的ip地址,即當(dāng)前unimrcp安裝的子網(wǎng)訪問(wèn)地址。 重新編譯安裝unimrcp(第二步 3)。 第四步 配置與驗(yàn)證配置配置FreeSWITCH 我們需要將處理用戶語(yǔ)音呼入的FreeSWITCH與向xfyun engine發(fā)請(qǐng)求的unimrcp server兩者連接起來(lái)。 1.配置unimrcp模塊并自動(dòng)加載; # 編輯/usr/local/src/freeswitch/modules.conf文件,找到要安裝的模塊,去掉前面的注釋符號(hào)# cd /usr/local/src/frerswitch vim modules.conf #asr_tts/mod_unimrcp asr_tts/mod_unimrcp # 執(zhí)行make mod_xxx-install命令,這樣就編譯相應(yīng)模塊,并把編譯后的動(dòng)態(tài)庫(kù)安裝的/usr/local/freeswitch/mod目錄下 make mod_unimrcp-install # 編輯/usr/local/freeswitch/conf/autoload_configs/modules.conf.xml,去掉注釋符號(hào),如果沒(méi)有發(fā)現(xiàn)對(duì)應(yīng)模塊,則添加 <load module="mod_unimrcp"> 2.設(shè)置profile文件與conf文件; 在/usr/local/freeswitch/conf/mrcp_profiles目錄新建unimrcpserver-mrcp-v2.xml配置文件: <include> <!-- UniMRCP Server MRCPv2 --> <!-- 后面我們使用該配置文件,均使用 name 作為唯一標(biāo)識(shí),而不是文件名 --> <profile name="unimrcpserver-mrcp2" version="2"> <!-- MRCP 服務(wù)器地址 --> <param name="server-ip" value="192.168.1.23"/> <!-- MRCP SIP 端口號(hào) --> <param name="server-port" value="8060"/> <param name="resource-location" value=""/> <!-- FreeSWITCH IP、端口以及 SIP 傳輸方式 --> <param name="client-ip" value="192.168.1.24" /> <param name="client-port" value="5069"/> <param name="sip-transport" value="udp"/> <param name="speechsynth" value="speechsynthesizer"/> <param name="speechrecog" value="speechrecognizer"/> <!--param name="rtp-ext-ip" value="auto"/--> <param name="rtp-ip" value="192.168.1.24"/> <param name="rtp-port-min" value="4000"/> <param name="rtp-port-max" value="5000"/> <param name="codecs" value="PCMU PCMA L16/96/8000"/> <!-- Add any default MRCP params for SPEAK requests here --> <synthparams> </synthparams> <!-- Add any default MRCP params for RECOGNIZE requests here --> <recogparams> <!--param name="start-input-timers" value="false"/--> </recogparams> </profile> </include> 配置/usr/local/freeswitch/conf/autoload_configs/unimrcp.conf.xml文件: <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>
3.配置IVR與腳本。 在/usr/local/freeswitch/conf/dialplan/default.xml里新增如下配置: <extension name="unimrcp"> <condition field="destination_number" ="^5001$"> <action application="answer"/> <action application="lua" data="names.lua"/> </condition> </extension> 在/usr/local/freeswitch/scripts目錄下新增names.lua腳本: session:answer() --freeswitch.consoleLog("INFO", "Called extension is '".. argv[1]"'\n") welcome = "ivr/ivr-welcome_to_freeswitch.wav" menu = "ivr/ivr-this_ivr_will_let_you_test_features.wav" -- grammar = "hello" no_input_timeout = 80000 recognition_timeout = 80000 confidence_threshold = 0.2 -- session:streamFile(welcome) --freeswitch.consoleLog("INFO", "Prompt file is \n") tryagain = 1 while (tryagain == 1) do -- session:execute("play_and_detect_speech",menu .. "detect:unimrcp {start-input-timers=false,no-input-timeout=" .. no_input_timeout .. ",recognition-timeout=" .. recognition_timeout .. "}" .. grammar) xml = session:getVariable('detect_speech_result') -- if (xml == nil) then freeswitch.consoleLog("CRIT","Result is 'nil'\n") tryagain = 0 else freeswitch.consoleLog("CRIT","Result is '" .. xml .. "'\n") tryagain = 0 end end -- -- put logic to forward call here -- session:sleep(250) session:set_tts_parms("unimrcp", "xiaofang"); session:speak("今天天氣不錯(cuò)啊"); session:hangup() 我們需要在/usr/local/freeswitch/grammar目錄新增hello.gram語(yǔ)法文件,可以為空語(yǔ)法文件須滿足語(yǔ)音識(shí)別語(yǔ)法規(guī)范1.0標(biāo)準(zhǔn)(簡(jiǎn)稱 SRGS1.0),該語(yǔ)法文件 ASR 引擎在進(jìn)行識(shí)別時(shí)可以使用。 <?xml version="1.0" encoding="utf-8" ?> <grammar version="1.0" xml:lang="zh-cn" root="Menu" tag-format="semantics/1.0" xmlns=http://www./2001/06/grammar xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions"><!- 這些都是必不可少的--> <rule id="city" scope="public"> <one-of> <!-- 匹配其中一個(gè)短語(yǔ)--> <item>北京</item> <item>上海</item> </one-of> </rule> <rule id="cross" scope="public"> <one-of> <item>到</item> <item>至</item> <item>飛往</item> </one-of> </rule> <rule id="Menu" scope="public"> <item> <ruleref uri="#date"/> <!--指定關(guān)聯(lián)的其他規(guī)則的節(jié)點(diǎn)--> <tag>out.date = reles.latest();</tag> </item> <item repeat="0-1">從</item> <!--顯示1次或0次--> <item> <ruleref uri="#city"/> <tag>out.city = rulels.latest();</tag> </item> <item> <ruleref uri="#cross"/> <tag>out.cross = rulels.latest();</tag> </item> <item> <ruleref uri="#city"/> <tag>out.city = rulels.latest();</tag> </item> </rule> </grammar>
驗(yàn)證下載測(cè)試工具:Adore SIP Client 在App Store(其他手機(jī)系統(tǒng)請(qǐng)到對(duì)應(yīng)應(yīng)用市場(chǎng))中搜索“Adore SIP Client”,并下載。 其中SIP IP是FreeSWITCH服務(wù)開(kāi)啟的主機(jī)IP與port(默認(rèn)為5060),USER NAME如上所述可選1000-1019,PASSWORD默認(rèn)為1234。點(diǎn)擊"Login"(請(qǐng)確保手機(jī)連接的網(wǎng)絡(luò)與FreeSWITCH在同一個(gè)子網(wǎng)內(nèi)),并撥打5001進(jìn)行語(yǔ)言測(cè)試驗(yàn)證(如果您是從第一步跳轉(zhuǎn)過(guò)來(lái)的,請(qǐng)撥打5000)。 其他相關(guān)資料FreeSWITCH主頁(yè):https:/// Unimrcp主頁(yè):http://www./ Apache APR:https://apr./ 訊飛SDK包導(dǎo)入方式:https://doc./msc_linux/SDK%E5%8C%85%E5%AF%BC%E5%85%A5.html |
|
|