步骤一:下载中文语音包
1,官方下载:下载
2,Github下载:下载
步骤二:创建中文包路径
mkdir /usr/share/freeswitch/sounds/zh/cn/link
步骤三:编译安装mod_say_zh
1,编译安装
cd /usr/local/src/freeswitch/src/mod/say/mod_say_zh
make && make install
2,查看模块是否已安装
安装目录下模块文件是否存在:
ls -l /usr/local/freeswitch/mod/ | grep mod_say_zh
安装目录
3,模块设置为启动时自动加载:
修改/usr/local/freeswitch/conf/autoload_configs/modules.conf.xml,将模块所在行的<!--
和-->
注释符去掉,即将<!-- <load module="mod_say_zh"/> -->
修改为:
<!-- Say -->
<load module="mod_say_en"/>
<load module="mod_say_zh"/>
步骤四:创建中文语言配置
1,创建配置文件
cd /usr/local/freeswitch/conf/lang/
cp -fr en zh
cd zh
mv en.xml zh.xml
2,修改zh.xml的内容
<language name="zh" say-module="zh" sound-prefix="$${sounds_dir}/zh/cn/link" tts-engine="mod_tts_commandline" tts-voice="link">
3,配置中文资源路径
开始修改fs的配置文件了 /usr/local/freeswitch/conf/vars.xml
<X-PRE-PROCESS cmd="set" data="sound_prefix=$${sounds_dir}/zh/cn/link"/>
<X-PRE-PROCESS cmd="set" data="default_language=zh"/>
<X-PRE-PROCESS cmd="set" data="default_dialect=cn"/>
<X-PRE-PROCESS cmd="set" data="default_voice=link"/>
4,FreeSWITCH加载中文语言配置
在/usr/local/freeswitch/conf/freeswitch.xml中<section name="languages" description="Language Management">
这一节点内增加:
<X-PRE-PROCESS cmd="include" data="lang/zh/*.xml"/>
步骤五: 重启FreeSWITCH或如下手动加载模块:
/usr/local/freeswitch/bin/fs_cli
load mod_say_zh
reloadxml
步骤六:验证
1,修改Dialplan拨号计划
在/usr/local/freeswitch/conf/dialplan/default.xml的<context name="default">
这一节点内增加:
<!--say测试-->
<extension name="socket_767_example">
<condition field="destination_number" expression="^767\d+$">
<action application="answer"/>
<action application="say" data="zh name_spelled intered 3456789"></action>
<action application="say" data="en NUMBER intered 3456789"></action>
<action application="say" data="zh TELEPHONE_NUMBER intered 13781655437"></action>
<action application="playback" data="voicemail/vm-goodbye.wav"></action>
</condition>
</extension>
2,配置生效
/usr/local/freeswitch/bin/fs_cli reloadxml
步骤七:中英文切换
1,把en.xml中的sound-prefix=sound-prefix="$${sound_prefix}"调整为:
<include>
<language name="en" say-module="en" sound-prefix="$${sounds_dir}/en/us/callie" tts-engine="cepstral" tts-voice="callie">
<phrases>
<macros>
<X-PRE-PROCESS cmd="include" data="demo/*.xml"/> <!-- Note: this now grabs whole subdir, previously grabbed only demo.xml -->
<!-- voicemail_en_tts is purely implemented with tts, we have the files based one that is the default. -->
<X-PRE-PROCESS cmd="include" data="vm/sounds.xml"/> <!-- vm/tts.xml if you want to use tts and have cepstral -->
<X-PRE-PROCESS cmd="include" data="dir/sounds.xml"/> <!-- dir/tts.xml if you want to use tts and have cepstral -->
<X-PRE-PROCESS cmd="include" data="ivr/*.xml"/> <!-- IVR and custom phrases go here -->
</macros>
<X-PRE-PROCESS cmd="include" data="vm/voicemail_ivr.xml"/>
</phrases>
</language>
</include>
如果为$${sound_prefix} 则表示引用的全局变量,该变量在vars.xml中有定义
<X-PRE-PROCESS cmd="set" data="sound_prefix=$${sounds_dir}/zh/cn/link"/>
所以需要调整为:sound-prefix="$${sounds_dir}/en/us/callie" 相对路径,英文的语音包
2,zh.xml文件内容如下:
<include>
<language name="zh" say-module="zh" sound-prefix="$${sounds_dir}/zh/cn/link" tts-engine="mod_tts_commandline" tts-voice="link">
<phrases>
<macros>
<X-PRE-PROCESS cmd="include" data="demo/*.xml"/> <!-- Note: this now grabs whole subdir, previously grabbed only demo.xml -->
<!-- voicemail_en_tts is purely implemented with tts, we have the files based one that is the default. -->
<X-PRE-PROCESS cmd="include" data="vm/sounds.xml"/> <!-- vm/tts.xml if you want to use tts and have cepstral -->
<X-PRE-PROCESS cmd="include" data="dir/sounds.xml"/> <!-- dir/tts.xml if you want to use tts and have cepstral -->
<X-PRE-PROCESS cmd="include" data="ivr/*.xml"/> <!-- IVR and custom phrases go here -->
</macros>
<X-PRE-PROCESS cmd="include" data="vm/voicemail_ivr.xml"/>
</phrases>
</language>
</include>
3,拨号计划调整,实现中英文切换
<!--say测试-->
<extension name="socket_767_example">
<condition field="destination_number" expression="^767\d+$">
<action application="answer"/>
<action application="say" data="en name_spelled intered 3456789abck"></action>
<action application="say" data="zh NUMBER ITERATED 13781655437"></action>
<action application="playback" data="voicemail/vm-goodbye.wav"></action>
</condition>
</extension>
本文在Say中通过en或zh指定使用哪种语音播放,然后指定引擎进行播放,如果引擎指定失败会播放失败
步骤八:中文语音包的使用
1,dialplan中配置
在dialplan中加入以下配置 <action application="set" data="language=zh"/>,说明该拨号计划使用中文语音
<extension name="ivr_demo">
<condition field="destination_number" expression="^5000$">
<action application="set" data="language=zh"/>
<action application="answer"/>
<action application="sleep" data="2000"/>
<action application="ivr" data="demo_ivr"/>
</condition>
</extension>
2,单个用户配置
例如配置1002.xml的variables标签中添加如下配置,让语言仅对1002用户生效。
<variable name="language" value="zh"/>
<variable name="default_language" value="zh"/>