# Text to BlendShapes API 将文字转换为52个形态键的API服务 ## 功能 1. 文字 → 音频 (使用 gTTS) 2. 音频 → CSV (使用 Audio2Face) 3. CSV → 52个形态键数据 ## 安装 ```bash cd a2f_api pip install -r requirements.txt ``` ## 使用 ```bash python api.py ``` 服务将在 `http://localhost:5001` 启动 ## API 接口 ### POST /text-to-blendshapes **请求:** ```json { "text": "你好世界", "language": "zh-CN" } ``` **响应:** ```json { "success": true, "frames": [ { "timeCode": 0.0, "blendShapes": { "EyeBlinkLeft": 0.0, "EyeLookDownLeft": 0.0, ... "TongueOut": 0.0 } } ], "audio_path": "...", "csv_path": "..." } ``` ### POST /text-to-blendshapes/stream **说明:** 使用 NDJSON 流式返回,便于边收边播放。 **响应:** 每行一个 JSON 对象,`type` 字段取值如下: - `status` - 阶段提示 - `frame` - 单帧数据 - `end` - 完成信息 - `error` - 错误信息 **示例:** ```json {"type":"status","stage":"tts","message":"Generating audio"} {"type":"frame","frame":{"timeCode":0.0,"blendShapes":{"JawOpen":0.1}}} {"type":"end","frames":900,"audio_path":"...","csv_path":"..."} ``` ## 文件说明 - `tts_service.py` - 文字转音频服务 - `a2f_service.py` - Audio2Face包装器 - `blend_shape_parser.py` - CSV解析器 - `text_to_blendshapes_service.py` - 主服务 - `api.py` - Flask API