Finalize only on final results
This commit is contained in:
@@ -34,7 +34,6 @@ function App() {
|
|||||||
const isRecordingRef = useRef(false)
|
const isRecordingRef = useRef(false)
|
||||||
const lastResultAtRef = useRef<number>(Date.now())
|
const lastResultAtRef = useRef<number>(Date.now())
|
||||||
const restartLockRef = useRef(false)
|
const restartLockRef = useRef(false)
|
||||||
const finalizeTimerRef = useRef<number | null>(null)
|
|
||||||
const isStartingRef = useRef(false)
|
const isStartingRef = useRef(false)
|
||||||
|
|
||||||
const hasSpeechRecognition = useMemo(() => {
|
const hasSpeechRecognition = useMemo(() => {
|
||||||
@@ -129,13 +128,6 @@ function App() {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
if (finalizeTimerRef.current) {
|
|
||||||
window.clearTimeout(finalizeTimerRef.current)
|
|
||||||
}
|
|
||||||
finalizeTimerRef.current = window.setTimeout(() => {
|
|
||||||
void commitLiveIfAny()
|
|
||||||
finalizeTimerRef.current = null
|
|
||||||
}, 1200)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,11 +136,6 @@ function App() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
recognition.onend = () => {
|
recognition.onend = () => {
|
||||||
if (finalizeTimerRef.current) {
|
|
||||||
window.clearTimeout(finalizeTimerRef.current)
|
|
||||||
finalizeTimerRef.current = null
|
|
||||||
}
|
|
||||||
void commitLiveIfAny()
|
|
||||||
liveTextRef.current = ''
|
liveTextRef.current = ''
|
||||||
if (isRecordingRef.current) {
|
if (isRecordingRef.current) {
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
@@ -177,10 +164,6 @@ function App() {
|
|||||||
const handleFinalTranscript = async (text: string) => {
|
const handleFinalTranscript = async (text: string) => {
|
||||||
const trimmed = text.trim()
|
const trimmed = text.trim()
|
||||||
if (!trimmed) return
|
if (!trimmed) return
|
||||||
if (finalizeTimerRef.current) {
|
|
||||||
window.clearTimeout(finalizeTimerRef.current)
|
|
||||||
finalizeTimerRef.current = null
|
|
||||||
}
|
|
||||||
lastResultAtRef.current = Date.now()
|
lastResultAtRef.current = Date.now()
|
||||||
const ts = new Date().toISOString()
|
const ts = new Date().toISOString()
|
||||||
liveTextRef.current = ''
|
liveTextRef.current = ''
|
||||||
|
|||||||
Reference in New Issue
Block a user