Skip to content

Commit 05341a0

Browse files
committed
fix
1 parent 5b36bdf commit 05341a0

File tree

7 files changed

+39
-48
lines changed

7 files changed

+39
-48
lines changed

apps/desktop/src/components/right-panel/hooks/useTranscript.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ export function useTranscript(sessionId: string | null) {
5656

5757
listenerEvents.sessionEvent.listen(({ payload }) => {
5858
if (payload.type === "finalWords") {
59-
setFinalWords(payload.words as Word[]);
59+
setFinalWords((existing) => [...existing, ...payload.words]);
6060
} else if (payload.type === "partialWords") {
61-
setPartialWords((payload.words as Word[]).map(w => ({ ...w, confidence: 0 })));
61+
setPartialWords((payload.words as Word[]).map(w => ({ ...w, confidence: -1 })));
6262
}
6363
}).then((fn) => {
6464
unlisten = fn;

apps/desktop/src/routes/app.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ function RestartSTT() {
166166
const sttPath = await localSttCommands.modelsDir();
167167

168168
return watch(sttPath, (_event) => {
169-
localSttCommands.stopServer("internal").then((stopped) => {
169+
localSttCommands.stopServer(null).then((stopped) => {
170170
if (stopped) {
171-
localSttCommands.startServer("internal");
171+
localSttCommands.getCurrentModel().then((model) => {
172+
localSttCommands.startServer(model);
173+
});
172174
}
173175
});
174176
}, { delayMs: 1000 });

packages/tiptap/src/styles/transcript.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
outline: 2px solid #4a9af4;
4646
}
4747

48-
span[data-confidence^="0"] {
48+
span[data-interim] {
4949
opacity: 0.3;
5050
color: #666;
5151
}

packages/tiptap/src/transcript/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { EditorContent, useEditor } from "@tiptap/react";
1010
import { forwardRef, useEffect, useRef } from "react";
1111

1212
import { SpeakerSplit } from "./extensions";
13-
import { ConfidenceMark } from "./marks";
13+
import { InterimMark } from "./marks";
1414
import { SpeakerNode } from "./nodes";
1515
import { fromEditorToWords, fromWordsToEditor, getSpeakerLabel, type SpeakerAttributes, type Word2 } from "./utils";
1616
import type { SpeakerChangeRange, SpeakerViewInnerComponent, SpeakerViewInnerProps } from "./views";
@@ -52,7 +52,7 @@ const TranscriptEditor = forwardRef<TranscriptEditorRef, TranscriptEditorProps>(
5252
Document.configure({ content: "speaker+" }),
5353
History,
5454
Text,
55-
ConfidenceMark,
55+
InterimMark,
5656
SpeakerNode(c),
5757
SpeakerSplit,
5858
SearchAndReplace.configure({

packages/tiptap/src/transcript/marks.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { Mark, mergeAttributes } from "@tiptap/core";
22

3-
export const ConfidenceMark = Mark.create({
4-
name: "confidence",
3+
export const InterimMark = Mark.create({
4+
name: "interim",
55

66
addAttributes() {
77
return {
8-
confidence: {
8+
interim: {
99
default: null,
1010
parseHTML: element => {
11-
const value = element.getAttribute("data-confidence");
11+
const value = element.getAttribute("data-interim");
1212
return value ? parseFloat(value) : null;
1313
},
1414
renderHTML: attributes => {
15-
if (attributes.confidence === null) {
15+
if (attributes.interim === null) {
1616
return {};
1717
}
1818
return {
19-
"data-confidence": attributes.confidence,
19+
"data-interim": attributes.interim,
2020
};
2121
},
2222
},
@@ -26,7 +26,7 @@ export const ConfidenceMark = Mark.create({
2626
parseHTML() {
2727
return [
2828
{
29-
tag: "span[data-confidence]",
29+
tag: "span[data-interim]",
3030
},
3131
];
3232
},

packages/tiptap/src/transcript/utils.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ export const fromWordsToEditor = (words: Word2[]): DocContent => {
6767
lastSpeaker.content.push({ type: "text", text: " " });
6868
}
6969

70-
if (word.confidence !== null) {
70+
if (word.confidence !== null && word.confidence < 0) {
7171
lastSpeaker.content.push({
7272
type: "text",
7373
text: word.text,
7474
marks: [
7575
{
76-
type: "confidence",
76+
type: "interim",
7777
attrs: {
78-
confidence: word.confidence,
78+
interim: true,
7979
},
8080
},
8181
],
@@ -126,16 +126,13 @@ export const fromEditorToWords = (content: DocContent | JSONContent): Word2[] =>
126126
continue;
127127
}
128128

129-
const confidenceMark = node.marks?.find((mark: any) => mark.type === "confidence");
130-
const confidence = confidenceMark?.attrs?.confidence ?? null;
131-
132129
const wordTexts = node.text.split(/\s+/).filter(Boolean);
133130

134131
for (const wordText of wordTexts) {
135132
words.push({
136133
text: wordText,
137134
speaker,
138-
confidence,
135+
confidence: null,
139136
start_ms: null,
140137
end_ms: null,
141138
});

plugins/listener/src/manager.rs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
pub struct TranscriptManager {
33
id: uuid::Uuid,
44
partial_words: Vec<owhisper_interface::Word>,
5-
final_words: Vec<owhisper_interface::Word>,
65
}
76

87
#[derive(Debug, Default, Clone)]
@@ -36,8 +35,6 @@ impl TranscriptManager {
3635
#[cfg(debug_assertions)]
3736
Self::log(self.id, &response);
3837

39-
let mut diff = Diff::default();
40-
4138
if let owhisper_interface::StreamResponse::TranscriptResponse {
4239
is_final, channel, ..
4340
} = response
@@ -57,36 +54,31 @@ impl TranscriptManager {
5754
.collect::<Vec<_>>();
5855

5956
if is_final {
60-
self.process_final_words(&mut diff, words);
57+
let last_final_word_end = words.last().unwrap().end;
58+
let partial_words = self
59+
.partial_words
60+
.iter()
61+
.filter(|w| w.start > last_final_word_end)
62+
.cloned()
63+
.collect::<Vec<_>>();
64+
65+
return Diff {
66+
final_words: words.clone(),
67+
partial_words,
68+
};
6169
} else {
62-
self.process_partial_words(&mut diff, words);
70+
self.partial_words = words.clone();
71+
72+
return Diff {
73+
final_words: vec![],
74+
partial_words: words.clone(),
75+
};
6376
}
6477
}
6578

66-
diff
67-
}
68-
69-
fn process_final_words(&mut self, diff: &mut Diff, words: &Vec<owhisper_interface::Word>) {
70-
diff.final_words = words.clone();
71-
self.final_words.extend(words.clone());
72-
self.partial_words.clear();
79+
Diff::default()
7380
}
7481

75-
fn process_partial_words(&mut self, diff: &mut Diff, words: &Vec<owhisper_interface::Word>) {
76-
let last_final_end = self.get_last_final_end_time();
77-
78-
self.partial_words = words
79-
.into_iter()
80-
.filter(|w| w.end > last_final_end)
81-
.cloned()
82-
.collect();
83-
84-
diff.partial_words = self.partial_words.clone();
85-
}
86-
87-
fn get_last_final_end_time(&self) -> f64 {
88-
self.final_words.last().map(|w| w.end).unwrap_or(0.0)
89-
}
9082
fn log(id: uuid::Uuid, response: &owhisper_interface::StreamResponse) {
9183
use std::fs::OpenOptions;
9284
use std::io::Write;

0 commit comments

Comments
 (0)