Send speech audio as normalized PCM frames

- Resample microphone input from the actual browser AudioContext sample rate to 16k before sending it to the speech proxy.

- Encode speech input as 16-bit PCM and send it in small 1280-byte frames instead of relying on the browser to create a 16k audio context.

- Flush pending audio before sending the standard Xunfei IAT end frame.

- Extract PCM helpers and cover downsampling, PCM encoding, base64 conversion, and byte concatenation with unit tests.

- Update report editor, testing, and progress documentation for the corrected speech audio pipeline.
This commit is contained in:
2026-05-02 06:30:56 +08:00
parent 87ab7d4b9c
commit 13d8853532
6 changed files with 128 additions and 26 deletions

View File

@@ -21,6 +21,7 @@ npm run build
| 前端 Dashboard API | 工作台统计封装会请求 `/api/dashboard/stats` 并校验响应结构。 |
| 前端审计 API | 审计日志列表封装会请求 `/api/audit-logs` 并校验响应结构。 |
| 前端语音代理地址 | 根据当前页面来源或 `VITE_API_BASE_URL` 生成 `/api/speech/iat` WebSocket 地址。 |
| 前端语音 PCM 处理 | 麦克风浮点音频会按实际采样率重采样为 16k、编码为 16bit PCM并按小帧拼接发送给讯飞代理。 |
| 前端字段库和文件 API | 字段库读取/更新、通用文件列表/上传封装。 |
| Auth 兼容映射 | 后端 `doctor` 角色会映射为当前前端使用的 `user`,并保留本地签名和模板授权。 |
| 权限展示 | 侧边栏和路由守卫会按角色显示或阻止模板管理、用户管理、审计日志等入口。 |
@@ -71,6 +72,7 @@ AI 第三方接口、讯飞语音上游 WebSocket、麦克风权限和真实视
| Dashboard API 封装 | 已覆盖 | `api/dashboard.test.ts` |
| 审计日志 API 封装 | 已覆盖 | `api/audit.test.ts` |
| 语音 WebSocket 代理地址 | 已覆盖 | `api/speech.test.ts` |
| 语音 PCM 重采样和编码 | 已覆盖 | `utils/audioPcm.test.ts` |
| 字段库 API 封装 | 已覆盖 | `api/library.test.ts` |
| 通用文件 API 封装 | 已覆盖 | `api/files.test.ts` |
| 后端用户到前端用户映射 | 已覆盖 | `auth/backendUser.test.ts` |
@@ -112,7 +114,7 @@ AI 第三方接口、讯飞语音上游 WebSocket、麦克风权限和真实视
| 报告编辑器完整流程 | 部分覆盖 | 已覆盖保存修订版本、个人模板和后端草稿/完成报告 schema模板切换、字段同步仍待补。 |
| 视频抽帧 | 待 E2E/人工 | 依赖真实视频解码和 canvas。 |
| AI 撰写 | 待集成测试 | 需要隔离外部模型服务。 |
| 讯飞语音听写 | 部分覆盖/待集成测试 | 已覆盖后端首帧处理;完整链路仍需要 WebSocket 集成测试、麦克风权限和测试凭证。 |
| 讯飞语音听写 | 部分覆盖/待集成测试 | 已覆盖前端 16k PCM 处理、后端首帧处理和 WebSocket 地址生成;完整链路仍需要 WebSocket 集成测试、麦克风权限和测试凭证。 |
## Playwright 说明