|
|
1 년 전 | |
|---|---|---|
| backend | 1 년 전 | |
| doubao-api | 1 년 전 | |
| frontend | 1 년 전 | |
| 提示词包 | 1 년 전 | |
| 需求 | 1 년 전 | |
| 项目文档 | 1 년 전 | |
| .DS_Store | 1 년 전 | |
| .cursorrules | 1 년 전 | |
| .gitignore | 1 년 전 | |
| HTTPS_SETUP.md | 1 년 전 | |
| IPHONE_STEP_BY_STEP.md | 1 년 전 | |
| IPHONE_TRUST_CERT.md | 1 년 전 | |
| MOBILE_SETUP.md | 1 년 전 | |
| NETWORK_CONFIG.md | 1 년 전 | |
| QUICK_START_HTTPS.md | 1 년 전 | |
| README.md | 1 년 전 | |
| configure-network.sh | 1 년 전 | |
| start-https.sh | 1 년 전 | |
| 优化总结.md | 1 년 전 | |
| 优化汇总-V2.md | 1 년 전 | |
| 快速响应优化-最终版.md | 1 년 전 | |
| 性能分析报告.md | 1 년 전 | |
| 无限循环修复.md | 1 년 전 | |
| 智能预播放优化.md | 1 년 전 | |
| 最终优化方案.md | 1 년 전 | |
| 最终方案-禁用预播放.md | 1 년 전 | |
| 流式播放-WebAudioAPI方案.md | 1 년 전 | |
| 流式播放优化说明.md | 1 년 전 | |
| 测试说明.md | 1 년 전 | |
| 移动端音量修复说明.md | 1 년 전 | |
| 紧急修复-死循环问题.md | 1 년 전 | |
| 豆包空闲超时自动重连修复.md | 1 년 전 | |
| 豆包超时错误修复.md | 1 년 전 | |
| 连接池耗尽修复.md | 1 년 전 | |
| 问题修复说明.md | 1 년 전 |
Tolan是一个基于AI的实时语音交互应用,用户可以通过与动画IP角色进行语音对话来练习英语口语。系统采用前后端分离架构,实现了低延迟(<300ms)的实时语音交互体验。
┌─────────────┐ WSS/HTTPS ┌─────────────┐ WebSocket ┌─────────────┐
│ 浏览器 │ ◄────────────────────── │ WSS服务器 │ ◄─────────────────── │ 豆包API │
│ (React) │ │ (FastAPI) │ │ │
│ │ ─────────────────────► │ │ ──────────────────► │ │
└─────────────┘ 实时音频流/控制消息 └─────────────┘ 实时音频流/控制消息 └─────────────┘
Tolan/
├── frontend/ # 前端应用(React + TypeScript)
│ ├── src/
│ │ ├── components/ # React组件
│ │ ├── stores/ # Zustand状态管理
│ │ ├── utils/ # 工具模块(WebSocket、录音、播放)
│ │ └── config.ts # 配置文件
│ ├── package.json
│ └── README.md
│
├── backend/ # 后端服务(FastAPI + Python)
│ ├── main.py # FastAPI主应用
│ ├── config.py # 配置管理
│ ├── connection_pool.py # 豆包API连接池
│ ├── websocket_handler.py # WebSocket处理器
│ ├── doubao_api/ # 豆包API模块
│ ├── requirements.txt
│ └── README.md
│
├── doubao-api/ # 豆包官方Demo
│ └── realtime_dialog_client.py
│
├── ssl/ # SSL证书
│ ├── cert.pem
│ └── key.pem
│
└── 项目文档/ # 项目文档
├── 用户需求分析书.md
├── 项目开发重点和难点分析.md
├── 开源组件推荐清单.md
└── API文档.md
git clone <repository-url>
cd Tolan
# 进入后端目录
cd backend
# 安装依赖(使用本机Python)
pip install -r requirements.txt
# 启动服务
python main.py
后端将在 http://localhost:8000 启动
# 新开终端,进入前端目录
cd frontend
# 安装依赖
npm install
# 启动开发服务器
npm run dev
前端将在 http://localhost:5173 启动
| 指标 | 目标值 | 实际值 |
|---|---|---|
| 端到端延迟 | < 300ms | 145-240ms ✅ |
| 前端采集延迟 | < 10ms | ~8ms ✅ |
| 网络传输延迟 | < 20ms | 10-20ms ✅ |
| 后端处理延迟 | < 10ms | ~5ms ✅ |
| 连接建立延迟 | 0ms | 0ms ✅ (连接池预热) |
// 使用Recorder.js实现跨平台录音
const recorder = new VoiceRecorder({
sampleRate: 16000,
bitRate: 16,
onProcess: (pcmData) => {
// 实时发送PCM数据
websocket.sendAudio(pcmData.buffer)
}
})
// 使用MediaSource API实现流式播放
const player = new StreamAudioPlayer()
await player.init()
// 边接收边播放
player.appendAudioChunk(audioData)
# 预创建连接,消除延迟
class DoubaoConnectionPool:
async def initialize(self):
# 预创建10个连接
for i in range(10):
conn = await create_connection()
await self.idle_connections.put(conn)
async def acquire(self):
# 零延迟获取连接
return await self.idle_connections.get()
# 并发处理音频流
await asyncio.gather(
receive_from_client(), # 接收客户端音频
send_to_doubao(), # 转发给豆包
receive_from_doubao(), # 接收豆包响应
send_to_client() # 发送给客户端
)
前端:
cd frontend
npm install
npm run dev
后端:
cd backend
pip install -r requirements.txt
python main.py
前端调试:
后端调试:
# 查看日志
tail -f backend/logs/app_*.log
# 健康检查
curl http://localhost:8000/health
麦克风权限被拒绝
WebSocket连接失败
音频无法播放
延迟过高
详细故障排查请参考各模块的文档。
后端已完成豆包API的真实集成,支持:
backend/.env 中配置python backend/main.py详细文档: backend/INTEGRATION_GUIDE.md
欢迎贡献代码、提出问题和建议!