AiSound 语音合成

简单易上手的 Python 调用教程

重要前提:必须安装 wxPython 才能正常使用窗体界面。
pip install wxPython
Python 版本要求:Python 3.9 32位(Python39-32
关键限制:当前项目只能用 32 位 Python 调用 aisound.dll

一、语音角色列表

以下是 aisound.dll 支持的所有语音角色:

编号标识符名称语言
01BabyXuBaby Xu普通话
02DaLong大龙粤语
03DonaldDuck唐老鸭普通话
04DuoXu多旭普通话
05JiuXu九旭普通话
06XiaoFeng小风普通话
07XiaoMei小美粤语
08XiaoPing小平普通话
09YanPing燕平普通话

二、DLL 函数接口

1. 初始化与终止

// 初始化语音引擎 bool aisound_initialize(); // 终止语音引擎,清理资源 void aisound_terminate();

2. 配置函数

// 配置语音引擎参数 // key: 配置项名称, value: 配置值 bool aisound_configure(const char* key, const char* value);

3. 语音合成控制

// 语音合成与播放 // text: 要合成的文本, user_data: 用户数据(可为 NULL) 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(确保 aisound.dll 在同目录) dll_path = os.path.join(os.path.dirname(__file__), "aisound.dll") dll = ctypes.CDLL(dll_path) # 1. 初始化 dll.aisound_initialize.restype = ctypes.c_bool if not dll.aisound_initialize(): print("初始化失败") exit() # 2. 配置语音角色 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") # 3. 播放语音 dll.aisound_speak.argtypes = [ctypes.c_char_p, ctypes.c_void_p] dll.aisound_speak.restype = ctypes.c_bool dll.aisound_speak(b"你好,世界!", None) # 4. 清理资源 dll.aisound_terminate()

六、注意事项