使用:
var rec = Recorder({
type: "pcm",
sampleRate: 16000,
bitRate: 16,
onProcess: function(buffers, level, time) {
// 实时传输音频数据
}
});
javascript
import ReconnectingWebSocket from 'reconnecting-websocket';
const ws = new ReconnectingWebSocket('wss://example.com');
socket.io-client (备选)
FastAPI ⭐推荐
@app.websocket("/ws") async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
**[python-socketio](https://github.com/miguelgrinberg/python-socketio)** (备选)
- Socket.IO Python实现
## 3. 音频播放
### 3.1 Web Audio封装
**[howler.js](https://github.com/goldfire/howler.js)**
- **优势**:
- 易用的音频播放API
- 跨浏览器兼容
- 支持音频队列
- 音量控制、淡入淡出
- **限制**: 不支持流式播放(需自定义)
**自定义Web Audio方案** ⭐推荐
- 使用原生Web Audio API
- 实现AudioBuffer队列
- 满足流式播放需求
### 3.2 流式音频播放
**[audio-streaming](https://github.com/rochars/audio-streaming)**
- 音频流播放参考
## 4. 前端框架与UI
### 4.1 框架选择
**[React](https://github.com/facebook/react)** ⭐推荐
- 配合TypeScript
- 生态丰富
**[Vue 3](https://github.com/vuejs/core)** (备选)
- 更简洁的语法
- Composition API
### 4.2 UI组件库
**PC端**:
- **[Ant Design](https://github.com/ant-design/ant-design)** - React
- **[Element Plus](https://github.com/element-plus/element-plus)** - Vue 3
**移动端**:
- **[Ant Design Mobile](https://github.com/ant-design/ant-design-mobile)** - React
- **[Vant](https://github.com/youzan/vant)** - Vue 3
**跨端**:
- **[Taro](https://github.com/NervJS/taro)** - 多端统一框架
### 4.3 状态管理
**React生态**:
- **[Zustand](https://github.com/pmndrs/zustand)** ⭐推荐
- 轻量级(1KB)
- API简单
- TypeScript友好
**Vue生态**:
- **[Pinia](https://github.com/vuejs/pinia)** ⭐推荐
- Vue 3官方推荐
- TypeScript支持好
## 5. 动画与交互
### 5.1 动画IP渲染
**[Lottie Web](https://github.com/airbnb/lottie-web)** ⭐推荐
- **优势**:
- After Effects动画直接导出
- 轻量级矢量动画
- 支持交互控制
- 跨平台
- **使用**:
```javascript
lottie.loadAnimation({
container: element,
renderer: 'svg',
loop: true,
autoplay: true,
path: 'animation.json'
});
Spine (备选)
PixiJS (备选)
Framer Motion - React
asyncio - Python内置
DashScope SDK ⭐推荐
pydub (备选)
Uvicorn ⭐推荐
Vite ⭐推荐
Webpack (备选)
TypeScript ⭐推荐
前端:
- React 18 + TypeScript
- Zustand (状态管理)
- Recorder.js (录音)
- Lottie Web (动画)
- Ant Design / Ant Design Mobile (UI)
- Vite (构建)
- reconnecting-websocket (通信)
后端:
- FastAPI + Python 3.9+
- DashScope SDK
- Uvicorn + Nginx
前端:
- Vue 3 + TypeScript
- Pinia (状态管理)
- Recorder.js (录音)
- Lottie Web (动画)
- Element Plus / Vant (UI)
- Vite (构建)
- reconnecting-websocket (通信)
后端:
- 同方案A
# 核心框架
npm install react react-dom
npm install -D @types/react @types/react-dom
# 状态管理
npm install zustand
# 录音
npm install recorder-core
# 动画
npm install lottie-web
# WebSocket
npm install reconnecting-websocket
# UI
npm install antd # PC
npm install antd-mobile # 移动
# 工具
npm install uuid
npm install lodash-es
# 开发工具
npm install -D vite @vitejs/plugin-react
npm install -D typescript
npm install -D eslint prettier
# 核心框架
pip install fastapi uvicorn[standard]
# 音频处理
pip install dashscope
# 异步HTTP
pip install aiohttp
# 工具
pip install python-dotenv
pip install pydantic
# 开发
pip install pytest
pip install black
react-lazy-load @loadable/component
P0必选:
P1推荐:
P2可选: