fix(voice): 浏览器语音默认走服务端 ASR

Web Speech 依赖 Google,国内浏览器常无法转文字;支持麦克风时改为录音后走自有 ASR,并补全网络异常时的降级匹配。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-06-29 12:34:34 +08:00
parent 0187f26c5b
commit 08c5b22d4a
2 changed files with 18 additions and 10 deletions
+4 -6
View File
@@ -1,10 +1,10 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { transcribeOneShot } from '../voice/asrTransport';
import { mapMicError } from '../voice/audioAnalyser';
import { shouldFallbackToServerAsr, shouldPreferServerAsr } from '../voice/capabilities';
import { shouldFallbackToServerAsr, shouldUseLiveSpeech } from '../voice/capabilities';
import { MicCapture } from '../voice/micCapture';
import { waitForMicRelease } from '../voice/micSession';
import { createLiveSpeechRecognition, isSpeechRecognitionSupported } from '../voice/speechRecognition';
import { createLiveSpeechRecognition } from '../voice/speechRecognition';
import type { VoiceSessionPhase } from '../voice/types';
const MIN_RECORD_MS = 500;
@@ -19,9 +19,7 @@ export function useVoiceSession({
const [phase, setPhase] = useState<VoiceSessionPhase>('idle');
const [text, setText] = useState('');
const [analyser, setAnalyser] = useState<AnalyserNode | null>(null);
const [liveRecognition, setLiveRecognition] = useState(
isSpeechRecognitionSupported() && !shouldPreferServerAsr(),
);
const [liveRecognition, setLiveRecognition] = useState(shouldUseLiveSpeech());
const committedRef = useRef('');
const interimRef = useRef('');
@@ -155,7 +153,7 @@ export function useVoiceSession({
if (sessionRef.current !== sessionId) return;
startedAtRef.current = Date.now();
const useLiveSpeech = isSpeechRecognitionSupported() && !shouldPreferServerAsr();
const useLiveSpeech = shouldUseLiveSpeech();
if (useLiveSpeech) {
const recognition = createLiveSpeechRecognition({