基于 CosyVoice3 的 LLM 语音对话 WebUI,支持流式 TTS 边生成边播放。
- 🎙️ 文本转语音 - 支持零音色克隆,使用参考音频生成语音
- 🤖 LLM 语音对话 - 对接 OpenAI 兼容接口的 LLM,实现语音对话
- ⚡ 流式输出 - 原生支持 CosyVoice 流式推理,边生成边播放
- 🌐 Web 界面 - 内置简洁的 WebUI,直接浏览器访问使用
git clone https://github.com/your-username/CosyVoice-Chat.git
cd CosyVoice-Chat# 克隆 CosyVoice 到项目目录
git clone https://github.com/FunAudioLLM/CosyVoice.git
cd CosyVoice按照 CosyVoice 官方文档安装依赖:
pip install -r requirements.txt下载预训练模型到 pretrained_models 目录:
# Fun-CosyVoice3-0.5B (推荐)
# 请参考 CosyVoice 官方文档下载模型
# 放置到 pretrained_models/Fun-CosyVoice3-0.5B 目录克隆 Matcha-TTS 到 third_party:
mkdir -p third_party
cd third_party
git clone https://github.com/yl4579/Matcha-TTS.git
cd ../..pip install fastapi uvicorn openai numpy soundfile torchaudio pydanticpython webui.py服务启动后访问:
- 文本转语音页面:http://localhost:8000/play
- LLM 语音对话页面:http://localhost:8000/chat
- API 文档:http://localhost:8000/docs
对话功能需要对接一个 OpenAI 兼容格式的 LLM API 服务。例如:
在网页中配置你的 LLM API 地址即可使用。
GET /- 服务健康检查POST /tts/stream- 文本转语音流式输出POST /tts/download- 文本转语音文件下载POST /chat/completion-stream- LLM 对话流式输出文字GET /chat/tts-pcm- TTS 流式输出 PCM 音频
CosyVoice-Chat/
├── webui.py # FastAPI Web服务
├── asset/ # 参考音频示例
├── pretrained_models/ # CosyVoice 模型
├── third_party/
│ └── Matcha-TTS/ # Matcha-TTS 依赖
└── README.md
- 需要 GPU 环境以获得较好的推理速度
- 模型体积较大,请确保有足够磁盘空间
- LLM 服务需要单独启动,本项目仅做对接
