Start STT immediately and drop answers
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import './App.css'
|
||||
import TranscriptPanel from './components/TranscriptPanel'
|
||||
import AnswerPanel from './components/AnswerPanel'
|
||||
import MeetingList from './components/MeetingList'
|
||||
import {
|
||||
createMeeting,
|
||||
@@ -19,7 +18,6 @@ function App() {
|
||||
const [transcriptLines, setTranscriptLines] = useState<
|
||||
{ id: number; ts: string; text: string; isFinal: boolean }[]
|
||||
>([])
|
||||
const [answerSuggestions, setAnswerSuggestions] = useState<string[]>([])
|
||||
const [meetingsList, setMeetingsList] = useState<
|
||||
{ id: number; started_at: string; ended_at: string | null; title: string | null }[]
|
||||
>([])
|
||||
@@ -32,6 +30,7 @@ function App() {
|
||||
const liveTextRef = useRef('')
|
||||
const lineIdRef = useRef(1)
|
||||
const meetingIdRef = useRef<number | null>(null)
|
||||
const pendingUtterancesRef = useRef<{ ts: string; text: string }[]>([])
|
||||
const isRecordingRef = useRef(false)
|
||||
const lastResultAtRef = useRef<number>(Date.now())
|
||||
const restartLockRef = useRef(false)
|
||||
@@ -61,7 +60,6 @@ function App() {
|
||||
}, [isRecording])
|
||||
|
||||
const commitLiveIfAny = async () => {
|
||||
if (!meetingIdRef.current) return
|
||||
const text = liveTextRef.current.trim()
|
||||
if (!text) return
|
||||
const ts = new Date().toISOString()
|
||||
@@ -75,6 +73,10 @@ function App() {
|
||||
}
|
||||
return [...prev, { id: lineIdRef.current++, ts, text, isFinal: true }]
|
||||
})
|
||||
if (!meetingIdRef.current) {
|
||||
pendingUtterancesRef.current.push({ ts, text })
|
||||
return
|
||||
}
|
||||
try {
|
||||
await saveUtterance(meetingIdRef.current, text, ts)
|
||||
} catch (err) {
|
||||
@@ -173,7 +175,6 @@ function App() {
|
||||
}
|
||||
|
||||
const handleFinalTranscript = async (text: string) => {
|
||||
if (!meetingIdRef.current) return
|
||||
const trimmed = text.trim()
|
||||
if (!trimmed) return
|
||||
if (finalizeTimerRef.current) {
|
||||
@@ -200,6 +201,10 @@ function App() {
|
||||
return nextLines
|
||||
})
|
||||
|
||||
if (!meetingIdRef.current) {
|
||||
pendingUtterancesRef.current.push({ ts, text: trimmed })
|
||||
return
|
||||
}
|
||||
try {
|
||||
await saveUtterance(meetingIdRef.current, trimmed, ts)
|
||||
} catch (err) {
|
||||
@@ -210,17 +215,24 @@ function App() {
|
||||
|
||||
const handleStart = async () => {
|
||||
setErrorMessage(null)
|
||||
lineIdRef.current = 1
|
||||
pendingUtterancesRef.current = []
|
||||
setTranscriptLines([])
|
||||
meetingIdRef.current = null
|
||||
setCurrentMeetingId(null)
|
||||
setIsRecording(true)
|
||||
isRecordingRef.current = true
|
||||
lastResultAtRef.current = Date.now()
|
||||
startRecognition()
|
||||
try {
|
||||
const result = await createMeeting(new Date().toISOString())
|
||||
meetingIdRef.current = result.id
|
||||
setCurrentMeetingId(result.id)
|
||||
lineIdRef.current = 1
|
||||
setTranscriptLines([])
|
||||
setAnswerSuggestions([])
|
||||
setIsRecording(true)
|
||||
isRecordingRef.current = true
|
||||
lastResultAtRef.current = Date.now()
|
||||
startRecognition()
|
||||
const pending = [...pendingUtterancesRef.current]
|
||||
pendingUtterancesRef.current = []
|
||||
await Promise.all(
|
||||
pending.map((item) => saveUtterance(result.id, item.text, item.ts))
|
||||
)
|
||||
} catch (err) {
|
||||
setErrorMessage((err as Error).message)
|
||||
}
|
||||
@@ -284,8 +296,6 @@ function App() {
|
||||
isFinal: true,
|
||||
}))
|
||||
)
|
||||
const lastAnswer = data.answers[data.answers.length - 1]
|
||||
setAnswerSuggestions(lastAnswer?.suggestions || [])
|
||||
} catch (err) {
|
||||
setErrorMessage((err as Error).message)
|
||||
}
|
||||
@@ -324,7 +334,6 @@ function App() {
|
||||
setCurrentMeetingId(null)
|
||||
meetingIdRef.current = null
|
||||
setTranscriptLines([])
|
||||
setAnswerSuggestions([])
|
||||
}
|
||||
} catch (err) {
|
||||
setErrorMessage((err as Error).message)
|
||||
@@ -336,7 +345,6 @@ function App() {
|
||||
<div className="left-panel">
|
||||
{errorMessage && <div className="error-banner">{errorMessage}</div>}
|
||||
<TranscriptPanel transcriptLines={transcriptLines} />
|
||||
<AnswerPanel suggestions={answerSuggestions} />
|
||||
<div className="controls">
|
||||
<button
|
||||
type="button"
|
||||
|
||||
Reference in New Issue
Block a user