数字人框架是一个模块化、可扩展的系统,集成了语音识别(ASR)、大语言模型(LLM)和语音合成(TTS)功能,为创建交互式数字人应用提供完整解决方案。该框架采用清晰的目录结构和标准化接口,确保各组件间无缝协作与灵活扩展。
- 模块化设计:ASR、LLM、TTS引擎可独立替换和扩展
- 异步处理:基于Python asyncio实现的高性能异步处理流程
- REST API:提供完整的REST API接口,支持文本和音频交互
- 配置灵活:基于YAML的配置系统,支持环境变量和配置合并
- 多引擎支持:
- ASR:支持FunASR本地模型
- LLM:支持OpenAI GPT系列模型
- TTS:支持Edge TTS和MiniMax TTS
+------------------+ +------------------+ +------------------+
| | | | | |
| ASR Engine +----->+ LLM Engine +----->+ TTS Engine |
| | | | | |
+------------------+ +------------------+ +------------------+
^ |
| |
| +------------------+ |
| | | |
+---------------+ Conversation +<---------------+
| Pipeline |
| |
+------------------+
^
|
|
+------------------+
| |
| FastAPI |
| Application |
| |
+------------------+
digital-human/
├── app.py # 主入口点
├── api/ # API接口
│ └── routes.py # API路由定义
├── configs/ # 配置文件
│ ├── default.yaml # 默认配置
│ └── engines/ # 引擎特定配置
│ ├── asr/ # ASR引擎配置
│ ├── llm/ # LLM引擎配置
│ └── tts/ # TTS引擎配置
├── engine/ # 引擎实现
│ ├── asr/ # ASR引擎
│ ├── llm/ # LLM引擎
│ └── tts/ # TTS引擎
├── integrations/ # 第三方集成
│ ├── deepgram.py # Deepgram集成
│ └── minimax.py # Minimax集成
├── pipelines/ # 处理管道
│ ├── conversation.py # 对话管道
│ └── speech.py # 语音处理
├── utils/ # 工具函数
│ └── audio_processor.py # 音频处理工具
└── test/ # 测试脚本
- Python 3.8+
- 依赖包:详见
requirements.txt
- 克隆项目:
git clone https://github.com/yourusername/digital-human.git
cd digital-human- 安装依赖:
pip install -r requirements.txt- 配置环境变量(可选):
# OpenAI API密钥(使用OpenAI LLM时需要)
export OPENAI_API_KEY=your_openai_api_key
# MiniMax API密钥(使用MiniMax TTS时需要)
export MINIMAX_API_KEY=your_minimax_api_key
export MINIMAX_GROUP_ID=your_minimax_group_id- 默认配置文件位于
configs/default.yaml - 引擎特定配置文件位于
configs/engines/{asr,llm,tts}/目录下 - 可通过环境变量
DH_CONFIG指定自定义配置文件路径
python app.py默认情况下,API服务会在http://0.0.0.0:8000上启动。您也可以使用以下参数自定义运行方式:
python app.py --config configs/custom.yaml --host 127.0.0.1 --port 8888GET /health
POST /api/chat/text
Content-Type: application/json
{
"text": "你好,请问你是谁?"
}
POST /api/chat/audio
Content-Type: application/json
{
"audio": "base64编码的音频数据",
"format": "mp3" # 音频格式:wav, mp3等
}
POST /api/asr
Content-Type: application/json
{
"audio": "base64编码的音频数据",
"format": "mp3" # 音频格式
}
POST /api/tts
Content-Type: application/json
{
"text": "要合成的文本内容"
}
项目提供了多个测试脚本,用于测试不同组件的功能:
test_asr.py:测试ASR引擎test_llm.py:测试LLM引擎test_tts.py:测试TTS引擎test_conversation_pipeline.py:测试完整对话流程test_api.py:测试API接口
# 测试ASR引擎
python test_asr.py
# 测试LLM引擎
python test_llm.py
# 测试TTS引擎
python test_tts.py
# 测试对话流程(使用文本输入)
python test_conversation_pipeline.py --text "你好,请问你是谁?"
# 测试对话流程(使用音频输入)
python test_conversation_pipeline.py --audio "test_outputs/advanced_audio_简短语音.mp3"
# 测试API接口
python test_api.py --test all- 在
engine/asr/目录下创建新的引擎实现类(如myASR.py) - 继承
BaseEngine类并实现必要的方法 - 使用
@ASREngines.register()装饰器注册引擎 - 在
configs/engines/asr/目录下创建对应的配置文件
示例:
from ..builder import ASREngines
from ..engineBase import BaseEngine
@ASREngines.register()
class MyASR(BaseEngine):
def checkKeys(self):
return ["NAME", "API_KEY"]
def setup(self):
# 初始化代码
pass
async def run(self, input, **kwargs):
# 实现语音识别逻辑
pass与添加ASR引擎类似,只需在相应目录下创建引擎实现类,并使用对应的装饰器注册。
欢迎提交问题报告和拉取请求。对于重大更改,请先开启一个问题讨论您要更改的内容。