feat: 支持无摄像头/麦克风模式打字聊天

- 修改 startSession 逻辑,摄像头和麦克风为可选
- 连接成功后始终显示聊天输入框
- 更新 UI 提示文字,引导用户打字对话
This commit is contained in:
2026-06-14 13:13:29 +08:00
parent dfccc824be
commit dffc8aa538
4 changed files with 37 additions and 17 deletions

View File

@@ -284,21 +284,26 @@ export function useVisionSession() {
/** 启动会话 */
const startSession = useCallback(async () => {
// 1. 获取摄像头和麦克风
await startCamera();
setIsCameraOn(true);
const micStream = await startMic();
if (!micStream) {
showToast("无法获取麦克风权限", "error");
return;
}
setIsMicOn(true);
// 2. 连接 WebSocket
// 1. 连接 WebSocket必须
connect();
// 3. 启动 VAD传入麦克风 stream
await startVAD(micStream);
// 2. 尝试获取摄像头(可选
try {
await startCamera();
setIsCameraOn(true);
} catch {
console.warn("[Session] 无法获取摄像头权限,将以纯文本模式运行");
}
// 3. 尝试获取麦克风(可选)
const micStream = await startMic();
if (micStream) {
setIsMicOn(true);
// 4. 启动 VAD仅在麦克风可用时
await startVAD(micStream);
} else {
console.warn("[Session] 无法获取麦克风权限,将以文本输入模式运行");
}
}, [startCamera, startMic, connect, startVAD]);
/** 结束会话 */