say 放音报错:Can't find language zh
FreeSWITCH say 模块中文语言配置错误排查
📋 问题描述
错误信息
1
| [ERR] switch_xml.c:3326 Can't find language zh
|
现象
在使用 FreeSWITCH 的 say 应用播放中文语音时出现语言找不到的错误。
测试命令:
1
| fs_cli -x "originate user/1002 &say('zh number pronounced 1234')"
|
预期行为: 播放中文数字语音 “1234”
实际行为: 报错 Can't find language zh
🔍 问题分析
根本原因
FreeSWITCH 无法找到中文(zh)语言配置,主要原因是:
- ❌ 缺少
/usr/local/freeswitch/conf/lang/zh/ 目录
- ❌ 缺少
zh.xml 语言配置文件
- ❌
mod_say_zh 模块引用的路径不存在
- ❌ 默认语言未设置为中文
涉及的文件和目录
1 2 3 4 5 6 7 8 9 10
| /usr/local/freeswitch/ ├── conf/ │ ├── lang/ │ │ ├── en/ # 英文语言目录 ✅ │ │ └── zh/ # 中文语言目录 ❌ (需要创建) │ ├── vars.xml # 全局变量配置 │ └── autoload_configs/ │ └── modules.conf.xml # 模块加载配置 └── mod/ └── mod_say_zh.so # 中文 say 模块
|
✅ 解决步骤
步骤 1: 检查语言目录是否存在
1 2 3 4 5 6 7 8 9
| ls -la /usr/local/freeswitch/conf/lang/
test -d /usr/local/freeswitch/conf/lang/zh && echo "存在" || echo "不存在"
|
步骤 2: 创建中文语言目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| sudo mkdir -p /usr/local/freeswitch/conf/lang/zh
sudo cp -r /usr/local/freeswitch/conf/lang/en /usr/local/freeswitch/conf/lang/zh
cd /usr/local/freeswitch/conf/lang/zh
sudo mv en.xml zh.xml
ls -la /usr/local/freeswitch/conf/lang/zh/
|
预期输出:
1 2 3 4 5 6 7
| drwxr-xr-x 2 root root 4096 Jan 28 18:00 . drwxr-xr-x 3 root root 4096 Jan 28 18:00 .. -rw-r--r-- 1 root root 1500 Jan 28 18:00 zh.xml drwxr-xr-x 4 root root 4096 Jan 28 18:00 demo drwxr-xr-x 2 root root 4096 Jan 28 18:00 dir drwxr-xr-x 2 root root 4096 Jan 28 18:00 ivr drwxr-xr-x 2 root root 4096 Jan 28 18:00 vm
|
步骤 3: 编辑 zh.xml 配置文件
文件路径: /usr/local/freeswitch/conf/lang/zh/zh.xml
1 2
| sudo vim /usr/local/freeswitch/conf/lang/zh/zh.xml
|
3.1 配置内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| <?xml version="1.0" encoding="UTF-8"?>
<include>
<language name="zh" say-module="zh" sound-prefix="$${sounds_dir}" tts-engine="cepstral" tts-voice="callie">
<phrases> <macros> <X-PRE-PROCESS cmd="include" data="demo/*.xml"/>
<X-PRE-PROCESS cmd="include" data="vm/sounds.xml"/>
<X-PRE-PROCESS cmd="include" data="dir/sounds.xml"/>
<X-PRE-PROCESS cmd="include" data="ivr/*.xml"/> </macros>
<X-PRE-PROCESS cmd="include" data="vm/voicemail_ivr.xml"/> </phrases>
</language> </include>
|
3.2 关键配置说明
⚠️ 注意:
say-module 必须与加载的模块名匹配
sound-prefix 使用 $${sounds_dir} 变量会自动解析
- TTS 相关配置可选,如果不需要 TTS 可以删除
步骤 4: 设置默认语言
4.1 检查 vars.xml
1 2 3 4
| grep "default_language" /usr/local/freeswitch/conf/vars.xml
|
4.2 编辑 vars.xml
1 2
| sudo vim /usr/local/freeswitch/conf/vars.xml
|
4.3 添加默认语言配置
在 <X-PRE-PROCESS> 部分添加以下行:
1 2 3 4 5
|
<X-PRE-PROCESS cmd="set" data="default_language=zh"/> <X-PRE-PROCESS cmd="set" data="default_dialect="cn"/>
|
完整的 vars.xml 示例:
1 2 3 4 5
| <X-PRE-PROCESS cmd="set" data="hold_music=local_stream://moh"/> <X-PRE-PROCESS cmd="set" data="default_areacode=86"/> <X-PRE-PROCESS cmd="set" data="default_language=zh"/> <X-PRE-PROCESS cmd="set" data="default_dialect=cn"/> <X-PRE-PROCESS cmd="set" data="international_dial_prefix=011"/>
|
步骤 5: 重载配置
1 2 3 4 5 6 7 8 9 10 11
| fs_cli
reloadxml
reload mod_say_zh
/exit
|
或者使用单行命令:
1 2
| fs_cli -x "reloadxml" fs_cli -x "reload mod_say_zh"
|
✅ 验证修复
验证 1: 检查语言目录
1 2 3 4 5 6 7 8 9 10 11
| ls -la /usr/local/freeswitch/conf/lang/ | grep zh
ls -la /usr/local/freeswitch/conf/lang/zh/zh.xml
|
验证 2: 检查模块加载
1 2 3 4 5 6 7 8 9 10 11 12
| fs_cli -x "module_exists mod_say_zh"
fs_cli -x "show modules" | grep say
|
验证 3: 测试 say 播放
测试 1: 数字播放
1 2 3 4 5 6 7
| fs_cli -x "originate user/1002 &say('zh number pronounced 1234')"
|
测试 2: 短语播放
1 2 3 4 5
| fs_cli -x "originate user/1002 &say('zh 您好')"
fs_cli -x "originate user/1002 &say('zh current time is 12点30分')"
|
测试 3: 在 Dialplan 中使用
1 2 3 4 5 6 7 8 9 10
| <extension name="play_chinese_number"> <condition field="destination_number" expression="^1234$"> <action application="answer"/> <action application="set" data="default_language=zh"/> <action application="set" data="default_dialect=cn"/> <action application="say" data="zh number pronounced 1234"/> <action application="hangup"/> </condition> </extension>
|
验证 4: 查看日志
1 2 3 4 5 6
| tail -f /usr/local/freeswitch/log/freeswitch.log | grep -E "zh|language|say"
|
🚨 常见问题排查
问题 1: 重载后仍然报错
现象:
1
| [ERR] switch_xml.c:3326 Can't find language zh
|
排查步骤:
1 2 3 4 5 6 7 8 9 10 11
| ls -ld /usr/local/freeswitch/conf/lang/zh
ls -l /usr/local/freeswitch/conf/lang/zh/zh.xml
xmllint --noout /usr/local/freeswitch/conf/lang/zh/zh.xml
grep "default_language" /usr/local/freeswitch/conf/vars.xml
|
解决方案:
1 2 3 4 5 6 7
| sudo mkdir -p /usr/local/freeswitch/conf/lang/zh sudo cp -r /usr/local/freeswitch/conf/lang/en/* /usr/local/freeswitch/conf/lang/zh/ sudo mv /usr/local/freeswitch/conf/lang/zh/en.xml /usr/local/freeswitch/conf/lang/zh/zh.xml
fs_cli -x "reloadxml"
|
问题 2: 模块加载失败
现象:
1 2
| fs_cli -x "module_exists mod_say_zh"
|
排查步骤:
1 2 3 4 5 6 7 8
| ls -l /usr/local/freeswitch/mod/mod_say_zh.so
fs_cli -x "load mod_say_zh"
tail -50 /usr/local/freeswitch/log/freeswitch.log | grep "mod_say_zh"
|
解决方案:
1 2 3 4 5 6 7
|
cd /usr/src/freeswitch make mod_say_zh make install
|
问题 3: 权限问题
现象:
1
| Permission denied accessing /usr/local/freeswitch/conf/lang/zh
|
排查步骤:
1 2 3 4 5 6 7 8
| ls -ld /usr/local/freeswitch/conf/lang/zh
ls -l /usr/local/freeswitch/conf/lang/zh/zh.xml
ls -l /usr/local/freeswitch/conf/lang/zh/ | head -5
|
解决方案:
1 2 3 4 5 6
| sudo chown -R freeswitch:freeswitch /usr/local/freeswitch/conf/lang/zh
sudo chmod -R 755 /usr/local/freeswitch/conf/lang/zh sudo chmod 644 /usr/local/freeswitch/conf/lang/zh/zh.xml
|
问题 4: 语音文件缺失
现象:
1
| File not found: /usr/local/freeswitch/sounds/zh/...
|
排查步骤:
1 2 3 4 5
| ls -la /usr/local/freeswitch/sounds/ | grep zh
fs_cli -x "eval \$\${sounds_dir}"
|
解决方案:
1 2 3 4 5 6 7 8
| sudo mkdir -p /usr/local/freeswitch/sounds/zh
sudo cp -r /usr/local/freeswitch/sounds/en/* /usr/local/freeswitch/sounds/zh/
|
问题 5: 多语言环境冲突
现象:
排查步骤:
1 2 3 4 5
| fs_cli -x "eval \$\${default_language}"
ls -la /usr/local/freeswitch/conf/lang/
|
解决方案:
📚 完整配置示例
zh.xml 完整配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <?xml version="1.0" encoding="UTF-8"?> <include> <language name="zh" say-module="zh" sound-prefix="$${sounds_dir}" tts-engine="cepstral" tts-voice="callie">
<phrases> <macros> <X-PRE-PROCESS cmd="include" data="demo/*.xml"/> <X-PRE-PROCESS cmd="include" data="vm/sounds.xml"/> <X-PRE-PROCESS cmd="include" data="dir/sounds.xml"/> <X-PRE-PROCESS cmd="include" data="ivr/*.xml"/> </macros> <X-PRE-PROCESS cmd="include" data="vm/voicemail_ivr.xml"/> </phrases>
</language> </include>
|
vars.xml 配置片段
1 2 3 4 5 6 7 8 9
|
<X-PRE-PROCESS cmd="set" data="default_language=zh"/> <X-PRE-PROCESS cmd="set" data="default_dialect=cn"/>
<X-PRE-PROCESS cmd="set" data="sound_prefix=$${sounds_dir}/en/us/callie"/> <X-PRE-PROCESS cmd="set" data="domain=$${local_ip_v4}"/>
|
Dialplan 使用示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <include> <extension name="say_demo"> <condition field="destination_number" expression="^2000$"> <action application="answer"/>
<action application="set" data="default_language=zh"/> <action application="set" data="default_dialect=cn"/>
<action application="playback" data="misc/welcome.wav"/>
<action application="say" data="zh number pronounced 1234"/>
<action application="hangup"/> </condition> </extension> </include>
|
📝 配置验证清单
🔗 相关文档
💡 最佳实践
- 备份原配置: 在复制 en 目录前备份原配置
- 逐步测试: 先测试数字播放,再测试复杂短语
- 权限管理: 确保所有文件和目录权限正确
- 日志监控: 配置修改后查看日志确认无错误
- 语音文件: 准备符合标准的中文语音文件
- 多语言环境: 确保不同语言配置不冲突
🎯 快速命令参考
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| ls -la /usr/local/freeswitch/conf/lang/ sudo mkdir -p /usr/local/freeswitch/conf/lang/zh sudo cp -r /usr/local/freeswitch/conf/lang/en \ /usr/local/freeswitch/conf/lang/zh sudo mv /usr/local/freeswitch/conf/lang/zh/en.xml \ /usr/local/freeswitch/conf/lang/zh/zh.xml
sudo chown -R freeswitch:freeswitch /usr/local/freeswitch/conf/lang/zh sudo chmod -R 755 /usr/local/freeswitch/conf/lang/zh sudo chmod 644 /usr/local/freeswitch/conf/lang/zh/zh.xml
xmllint --noout /usr/local/freeswitch/conf/lang/zh/zh.xml grep "default_language" /usr/local/freeswitch/conf/vars.xml
fs_cli -x "module_exists mod_say_zh" fs_cli -x "load mod_say_zh" fs_cli -x "reload mod_say_zh"
fs_cli -x "reloadxml"
fs_cli -x "originate user/1002 &say('zh number pronounced 1234')" tail -f /usr/local/freeswitch/log/freeswitch.log | grep -E "zh|language|say"
|
文档版本: v2.0
最后更新: 2026-01-28
维护者: FreeSWITCH 运维团队