Merge pull request '修复对话麦克风问题' (#64) from frontend-10 into develop

Reviewed-on: http://8.161.227.145:3000/XEngineers/CamTalk/pulls/64
This commit was merged in pull request #64.
This commit is contained in:
2026-06-14 13:08:46 +08:00
9 changed files with 262 additions and 76 deletions

View File

@@ -41,19 +41,22 @@ interface WsMessage {
#### `query` — 发起一次视觉对话
用户说完话后,客户端同时发送当前图像帧和语音片段:
用户说完话后,客户端同时发送当前图像帧和语音片段。也支持文本输入模式(手动输入文字时跳过语音识别)
```typescript
interface QueryMessage {
type: "query";
request_id: string; // 客户端生成的 UUID
image: string; // Base64 编码的 JPEG 图像(不含 data: 前缀)
audio: string; // Base64 编码的音频片段PCM 16kHz
audio: string; // Base64 编码的音频片段PCM 16kHz,文本输入时为空字符串
text?: string; // 用户手动输入的文本(有值时跳过 STT直接使用此文本
mime_type?: string; // 音频格式,默认 "audio/pcm"
}
```
> 为什么图像和音频放在同一条消息里?因为 VAD 检测到用户说完话时,需要同时捕获"此刻的画面"和"说的话",拆成两条消息会增加时序同步的复杂度。
>
> **文本输入模式**:当用户关闭麦克风后,可通过对话框手动输入文字。此时 `text` 字段携带用户输入,`audio` 为空字符串,服务端跳过 STT 直接使用 `text` 进行 LLM 推理。
#### `config` — 更新会话配置
@@ -211,13 +214,13 @@ interface PongMessage {
### 消息流时序
一次完整交互
**语音模式**(麦克风开启)
```
Client Server
| |
|-- query {image, audio} ------>|
|<-- stt_result {text} ---------|
|<-- stt_result {text} ---------| (语音识别)
| |
|<-- llm_chunk {delta: "这"} ---| (LLM 流式输出)
|<-- llm_chunk {delta: "是一"} -|
@@ -228,6 +231,22 @@ Client Server
|<-- tts_audio {is_last: true} -|
```
**文本输入模式**(麦克风关闭,手动输入文字):
```
Client Server
| |
|-- query {image, text} ------->| (跳过 STT)
|<-- stt_result {text} ---------| (回显用户文本)
| |
|<-- llm_chunk {delta: "好的"} -| (LLM 流式输出)
|<-- llm_chunk {delta: ",我"} -|
|<-- llm_done {full_text} ------|
| |
|<-- tts_audio {audio} ---------| (TTS 音频流)
|<-- tts_audio {is_last: true} -|
```
---
## 二、REST API
@@ -891,6 +910,7 @@ type QueryRequest struct {
RequestID string `json:"request_id"`
Image []byte `json:"-"` // Base64 解码后
Audio []byte `json:"-"` // Base64 解码后
Text string `json:"text"` // 用户手动输入的文本(有值时跳过 STT
MimeType string `json:"mime_type"`
}