AiSound 语音合成
简单易上手的 Python 调用教程
重要前提:必须安装 wxPython 才能正常使用窗体界面。
pip install wxPython
Python 版本要求:Python 3.9 32位(Python39-32)
关键限制:当前项目只能用 32 位 Python 调用 aisound.dll
一、语音角色列表
以下是 aisound.dll 支持的所有语音角色:
| 编号 | 标识符 | 名称 | 语言 |
| 01 | BabyXu | Baby Xu | 普通话 |
| 02 | DaLong | 大龙 | 粤语 |
| 03 | DonaldDuck | 唐老鸭 | 普通话 |
| 04 | DuoXu | 多旭 | 普通话 |
| 05 | JiuXu | 九旭 | 普通话 |
| 06 | XiaoFeng | 小风 | 普通话 |
| 07 | XiaoMei | 小美 | 粤语 |
| 08 | XiaoPing | 小平 | 普通话 |
| 09 | YanPing | 燕平 | 普通话 |
二、DLL 函数接口
1. 初始化与终止
bool aisound_initialize();
void aisound_terminate();
2. 配置函数
bool aisound_configure(const char* key, const char* value);
3. 语音合成控制
bool aisound_speak(const char* text, void* user_data);
bool aisound_cancel();
三、调用顺序
第 1 步:aisound_initialize() — 初始化引擎
第 2 步:aisound_configure() — 配置参数(如设置语音角色)
第 3 步:aisound_speak() — 播放语音
第 4 步(可选):aisound_cancel() — 停止播放
第 5 步:aisound_terminate() — 清理资源
四、配置示例
设置语音角色
aisound_configure("voice", "YanPing");
aisound_configure("voice", "DaLong");
五、完整 Python 示例
import ctypes
import os
dll_path = os.path.join(os.path.dirname(__file__), "aisound.dll")
dll = ctypes.CDLL(dll_path)
dll.aisound_initialize.restype = ctypes.c_bool
if not dll.aisound_initialize():
print("初始化失败")
exit()
dll.aisound_configure.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
dll.aisound_configure.restype = ctypes.c_bool
dll.aisound_configure(b"voice", b"YanPing")
dll.aisound_speak.argtypes = [ctypes.c_char_p, ctypes.c_void_p]
dll.aisound_speak.restype = ctypes.c_bool
dll.aisound_speak(b"你好,世界!", None)
dll.aisound_terminate()
六、注意事项
- 所有函数返回 bool 类型,表示操作是否成功
- 必须按顺序调用:先初始化,再配置,最后使用
- 使用完成后必须调用 aisound_terminate() 释放资源
- 文本编码应为 UTF-8
- 第二个参数 user_data 在示例中传递 NULL,可用于扩展功能
- 必须使用 32 位 Python 调用,64 位会报错