feat: template

This commit is contained in:
2026-01-29 11:41:03 -08:00
parent e6c19b589e
commit a6843cb3f1
3 changed files with 63 additions and 29 deletions
+26 -19
View File
@@ -165,7 +165,7 @@ function App() {
const stopRecording = async () => {
try {
// Stop the timers
// Stop the timers first
if (recordingTimer.current) {
clearInterval(recordingTimer.current);
recordingTimer.current = null;
@@ -178,36 +178,43 @@ function App() {
setAppState("transcribing");
setStatusMessage("Processing final audio...");
// Process any remaining audio
const finalChunk = await invoke<number[]>("get_remaining_audio", {
lastOffset: audioOffset.current
});
if (finalChunk.length > 0) {
const finalSegments = await invoke<TranscriptSegment[]>("transcribe_chunk", {
audioData: finalChunk
// First, process any audio that hasn't been processed yet
try {
const finalChunk = await invoke<number[]>("get_remaining_audio", {
lastOffset: audioOffset.current
});
if (finalSegments.length > 0) {
const baseTime = totalProcessedSamples.current / 16000;
const adjustedSegments = finalSegments.map(seg => ({
...seg,
start: seg.start + baseTime,
end: seg.end + baseTime,
}));
if (finalChunk.length > 0) {
console.log(`Processing final chunk of ${finalChunk.length} samples`);
const finalSegments = await invoke<TranscriptSegment[]>("transcribe_chunk", {
audioData: finalChunk
});
setTranscriptSegments(prev => [...prev, ...adjustedSegments]);
if (finalSegments.length > 0) {
const baseTime = totalProcessedSamples.current / 16000;
const adjustedSegments = finalSegments.map(seg => ({
...seg,
start: seg.start + baseTime,
end: seg.end + baseTime,
}));
setTranscriptSegments(prev => [...prev, ...adjustedSegments]);
}
}
} catch (chunkError) {
console.error("Error processing final chunk:", chunkError);
// Continue with stopping even if final chunk fails
}
// Stop the recording
await invoke("stop_recording");
// Now stop the recording
await invoke<string>("stop_recording");
setAppState("ready");
setStatusMessage("");
} catch (error) {
console.error("Failed to stop recording:", error);
setAppState("ready");
setStatusMessage("");
setErrorMessage(String(error));
}
};