able to re-transcribe
This commit is contained in:
@ -92,6 +92,7 @@ interface EditorActions {
|
||||
setTranscribing: (active: boolean, progress?: number, status?: string) => void;
|
||||
setExporting: (active: boolean, progress?: number) => void;
|
||||
setZonePreviewPaddingSeconds: (seconds: number) => void;
|
||||
replaceWordRange: (startIndex: number, endIndex: number, newWords: Word[]) => void;
|
||||
getKeepSegments: () => Array<{ start: number; end: number }>;
|
||||
getWordAtTime: (time: number) => number;
|
||||
loadProject: (projectData: any) => void;
|
||||
@ -473,6 +474,41 @@ export const useEditorStore = create<EditorState & EditorActions>()(
|
||||
set({ zonePreviewPaddingSeconds: nextSeconds });
|
||||
},
|
||||
|
||||
replaceWordRange: (startIndex, endIndex, newWords) => {
|
||||
const { words } = get();
|
||||
if (startIndex < 0 || endIndex >= words.length || startIndex > endIndex) return;
|
||||
|
||||
// Replace words in the range with new words
|
||||
const before = words.slice(0, startIndex);
|
||||
const after = words.slice(endIndex + 1);
|
||||
const updatedWords = [...before, ...newWords, ...after];
|
||||
|
||||
// Rebuild segments from updated words, grouping by speaker
|
||||
const rebuiltSegments: Segment[] = [];
|
||||
let wordIdx = 0;
|
||||
let cumIdx = 0;
|
||||
while (wordIdx < updatedWords.length) {
|
||||
const currentSpeaker = updatedWords[wordIdx].speaker;
|
||||
const groupWords: Word[] = [];
|
||||
while (wordIdx < updatedWords.length && updatedWords[wordIdx].speaker === currentSpeaker) {
|
||||
groupWords.push(updatedWords[wordIdx]);
|
||||
wordIdx++;
|
||||
}
|
||||
rebuiltSegments.push({
|
||||
id: rebuiltSegments.length,
|
||||
start: groupWords[0].start,
|
||||
end: groupWords[groupWords.length - 1].end,
|
||||
text: groupWords.map((w) => w.word).join(' '),
|
||||
words: groupWords,
|
||||
speaker: currentSpeaker,
|
||||
globalStartIndex: cumIdx,
|
||||
});
|
||||
cumIdx += groupWords.length;
|
||||
}
|
||||
|
||||
set({ words: updatedWords, segments: rebuiltSegments, selectedWordIndices: [] });
|
||||
},
|
||||
|
||||
getKeepSegments: () => {
|
||||
const { words, cutRanges, duration } = get();
|
||||
if (words.length === 0) return [{ start: 0, end: duration }];
|
||||
|
||||
Reference in New Issue
Block a user