Skip to content

Commit 17ece7d

Browse files
committed
first draft of adding segments to transcriptions
1 parent 93ce3e5 commit 17ece7d

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

composables/transcription.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,41 @@ export function useTranscriptionTool(options: UseTranscriptionToolOptions) {
181181
);
182182
}
183183

184+
function addSegment(index: number) {
185+
const followingSegment = editableTranscription.value[index];
186+
if (!followingSegment) return;
187+
const newSegment = {
188+
start: Math.max(
189+
editableTranscription.value[index - 1]?.end || 0,
190+
(followingSegment.start ?? 0) - 6,
191+
),
192+
end: followingSegment.start,
193+
text: "",
194+
isHeader: false,
195+
id: index,
196+
};
197+
editableTranscription.value.splice(index, 0, newSegment);
198+
transcription.value?.splice(index, 0, structuredClone(toRaw(newSegment)));
199+
for (let i = index; i < editableTranscription.value.length; i++) {
200+
editableTranscription.value[i].id = i;
201+
transcription.value[i].id = i;
202+
}
203+
}
204+
205+
function appendSegment() {
206+
const lastSegment = editableTranscription.value.at(-1);
207+
if (!lastSegment?.end) return;
208+
const newSegment = {
209+
start: lastSegment.end,
210+
end: lastSegment.end + 6,
211+
text: "",
212+
isHeader: false,
213+
id: editableTranscription.value.length,
214+
};
215+
editableTranscription.value.push(newSegment);
216+
transcription.value?.push(structuredClone(toRaw(newSegment)));
217+
}
218+
184219
return {
185220
currentIndex,
186221
transcription,
@@ -198,5 +233,7 @@ export function useTranscriptionTool(options: UseTranscriptionToolOptions) {
198233
toggleDeletion,
199234
deletedTranscriptionSegments,
200235
refetchTranscription,
236+
addSegment,
237+
appendSegment,
201238
};
202239
}

pages/transcribe/[id].vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ const {
8383
deletedTranscriptionSegments,
8484
refetchTranscription,
8585
syncEditableTranscription,
86+
addSegment,
87+
appendSegment,
8688
} = useTranscriptionTool({
8789
trackId: Number(route.params.id),
8890
language,
@@ -320,6 +322,30 @@ async function copyToClipboard() {
320322
}}
321323
</span>
322324
</button>
325+
<button
326+
v-if="
327+
!hasInvalidIds &&
328+
(index == 0 ||
329+
(item.start &&
330+
editableTranscription[index - 1]?.end &&
331+
item.start > editableTranscription[index - 1].end + 3))
332+
"
333+
class="flex items-center gap-0.5 rounded-full border border-label-separator px-1.5 hover:text-label-3"
334+
@click="addSegment(index)"
335+
>
336+
<NuxtIcon name="icon.close.small" class="opacity-50" />
337+
Insert Before
338+
</button>
339+
<button
340+
v-if="
341+
!hasInvalidIds && index == editableTranscription.length - 1
342+
"
343+
class="flex items-center gap-0.5 rounded-full border border-label-separator px-1.5 hover:text-label-3"
344+
@click="appendSegment()"
345+
>
346+
<NuxtIcon name="icon.close.small" class="opacity-50" />
347+
Insert After
348+
</button>
323349
<button
324350
v-if="!hasInvalidIds"
325351
:class="[

0 commit comments

Comments
 (0)