Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Add virtual scrolling to speaker modal for long transcriptions
Murtaza Nasirbd9dafad1e78
diff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex 41e92975..8c5e9d61 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -13,6 +13,7 @@ import { useSpeakers } from './modules/composables/speakers.js';import { useChat } from './modules/composables/chat.js';import { useTags } from './modules/composables/tags.js';import { usePWA } from './modules/composables/pwa.js';+import { useVirtualScroll, getVirtualItemKey } from './modules/composables/virtualScroll.js';// Import utilitiesimport { showToast } from './modules/utils/toast.js';@@ -383,6 +384,11 @@ document.addEventListener('DOMContentLoaded', async () => {const currentSpeakerGroupIndex = ref(0);const speakerGroups = ref([]);+ // --- Virtual Scroll Container Refs ---+ const speakerModalTranscriptRef = ref(null);+ const mainTranscriptRef = ref(null);+ const asrEditorRef = ref(null);+// --- Computed properties needed by composables ---const isMobileScreen = computed(() => windowWidth.value < 1024);const isMobileDevice = computed(() => {@@ -519,7 +525,10 @@ document.addEventListener('DOMContentLoaded', async () => {reprocessingPolls,// Speaker Groups- currentSpeakerGroupIndex, speakerGroups+ currentSpeakerGroupIndex, speakerGroups,++ // Virtual Scroll+ speakerModalTranscriptRef, mainTranscriptRef, asrEditorRef};// =========================================================================@@ -985,6 +994,37 @@ document.addEventListener('DOMContentLoaded', async () => {// Speakers composable needs processedTranscription, so initialize it afterconst speakersComposable = useSpeakers(state, utils, processedTranscription);+ // =========================================================================+ // VIRTUAL SCROLL SETUP (for performance with long transcriptions)+ // =========================================================================+ // Create a computed ref for the segments array+ const transcriptSegments = computed(() => processedTranscription.value.simpleSegments || []);++ // Virtual scroll for speaker modal transcript (main performance bottleneck)+ const speakerModalVirtualScroll = useVirtualScroll({+ items: transcriptSegments,+ itemHeight: 52, // Approximate height of each segment row+ containerRef: speakerModalTranscriptRef,+ overscan: 8+ });++ // Virtual scroll for main transcription panel+ const mainTranscriptVirtualScroll = useVirtualScroll({+ items: transcriptSegments,+ itemHeight: 48,+ containerRef: mainTranscriptRef,+ overscan: 5+ });++ // Helper to scroll to a segment by index (for speaker navigation)+ const scrollToSegmentIndex = (index) => {+ if (showSpeakerModal.value) {+ speakerModalVirtualScroll.scrollToIndex(index, 'smooth');+ } else {+ mainTranscriptVirtualScroll.scrollToIndex(index, 'smooth');+ }+ };+const groupedRecordings = computed(() => {const groups = {};const groupDates = {}; // Track the most recent date in each group@@ -1965,6 +2005,21 @@ document.addEventListener('DOMContentLoaded', async () => {getBubbleGlobalIndex,formatRecordingMode,+ // Virtual scroll+ speakerModalTranscriptRef,+ mainTranscriptRef,+ asrEditorRef,+ speakerModalVisibleSegments: speakerModalVirtualScroll.visibleItems,+ speakerModalSpacerBefore: speakerModalVirtualScroll.spacerBefore,+ speakerModalSpacerAfter: speakerModalVirtualScroll.spacerAfter,+ onSpeakerModalScroll: speakerModalVirtualScroll.onScroll,+ mainTranscriptVisibleSegments: mainTranscriptVirtualScroll.visibleItems,+ mainTranscriptSpacerBefore: mainTranscriptVirtualScroll.spacerBefore,+ mainTranscriptSpacerAfter: mainTranscriptVirtualScroll.spacerAfter,+ onMainTranscriptScroll: mainTranscriptVirtualScroll.onScroll,+ scrollToSegmentIndex,+ getVirtualItemKey,+// Recording recoveryshowRecoveryModal,recoverableRecording,diff --git a/templates/modals/speaker-modal.html b/templates/modals/speaker-modal.htmlindex 1e3c7789..c206ec7a 100644--- a/templates/modals/speaker-modal.html+++ b/templates/modals/speaker-modal.html@@ -175,10 +175,21 @@</div></div>- <!-- Transcript Section -->- <div class="flex-grow overflow-y-auto custom-scrollbar speaker-modal-transcript min-h-0" @click="seekAudioFromEvent">+ <!-- Transcript Section (Virtual Scrolling for performance) -->+ <div ref="speakerModalTranscriptRef"+ class="flex-grow overflow-y-auto custom-scrollbar speaker-modal-transcript min-h-0"+ @click="seekAudioFromEvent"+ @scroll="onSpeakerModalScroll"><div v-if="processedTranscription.isJson">- <div v-for="(segment, index) in processedTranscription.simpleSegments" :key="`seg-${index}-${segment.startTime}`" class="speaker-segment mb-1.5 sm:mb-2 group relative" :data-start-time="segment.startTime">+ <!-- Virtual scroll spacer (top) -->+ <div :style="{ height: speakerModalSpacerBefore + 'px' }"></div>++ <!-- Only render visible segments -->+ <div v-for="segment in speakerModalVisibleSegments"+ :key="getVirtualItemKey(segment, 'sm')"+ class="speaker-segment mb-1.5 sm:mb-2 group relative"+ :data-start-time="segment.startTime"+ :data-segment-index="segment._originalIndex"><div class="flex items-start gap-1"><!-- Speaker tag on its own line on mobile --><span :class="[segment.color, 'speaker-tag', { 'speaker-highlight': highlightedSpeaker === segment.speakerId }]" :data-speaker-id="segment.speakerId" class="inline-block flex-shrink-0 truncate text-xs sm:text-sm font-medium w-16 sm:w-24" :title="segment.speaker">${ segment.speaker }</span>@@ -186,26 +197,29 @@<span class="word cursor-pointer hover:bg-[var(--bg-accent)] hover:text-[var(--text-accent)] rounded px-0.5 flex-1 text-xs sm:text-sm leading-relaxed">${ segment.sentence }</span><!-- Edit buttons - inline on mobile --><span class="flex items-center gap-0.5 flex-shrink-0 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity">- <button @click.stop="openSpeakerChangeDropdown(index)" class="p-1 rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-accent)] text-[var(--text-muted)] hover:text-[var(--text-accent)] transition-colors active:scale-95" title="Change speaker">+ <button @click.stop="openSpeakerChangeDropdown(segment._originalIndex)" class="p-1 rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-accent)] text-[var(--text-muted)] hover:text-[var(--text-accent)] transition-colors active:scale-95" title="Change speaker"><i class="fas fa-user-edit text-[10px] sm:text-xs"></i></button>- <button @click.stop="openEditTextModal(index)" class="p-1 rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-accent)] text-[var(--text-muted)] hover:text-[var(--text-accent)] transition-colors active:scale-95" title="Edit text">+ <button @click.stop="openEditTextModal(segment._originalIndex)" class="p-1 rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-accent)] text-[var(--text-muted)] hover:text-[var(--text-accent)] transition-colors active:scale-95" title="Edit text"><i class="fas fa-edit text-[10px] sm:text-xs"></i></button></span></div><!-- Speaker Change Dropdown - compact on mobile -->- <div v-if="editingSpeakerIndex === index" @click.stop class="mt-1 p-1.5 bg-[var(--bg-tertiary)] rounded-md border border-[var(--border-primary)] shadow-lg">+ <div v-if="editingSpeakerIndex === segment._originalIndex" @click.stop class="mt-1 p-1.5 bg-[var(--bg-tertiary)] rounded-md border border-[var(--border-primary)] shadow-lg"><p class="text-[10px] text-[var(--text-muted)] mb-1">Select speaker:</p><div class="flex flex-wrap gap-1">- <button v-for="speaker in modalSpeakers" :key="speaker" @click="changeSpeaker(index, speaker)" class="px-2 py-1 rounded-md hover:bg-[var(--bg-accent)] hover:text-[var(--text-accent)] active:scale-[0.98] transition-all flex items-center gap-1 text-xs bg-[var(--bg-secondary)]">+ <button v-for="speaker in modalSpeakers" :key="speaker" @click="changeSpeaker(segment._originalIndex, speaker)" class="px-2 py-1 rounded-md hover:bg-[var(--bg-accent)] hover:text-[var(--text-accent)] active:scale-[0.98] transition-all flex items-center gap-1 text-xs bg-[var(--bg-secondary)]"><div :class="speakerMap[speaker].color" class="w-2.5 h-2.5 rounded-full flex-shrink-0"></div><span class="truncate max-w-[60px]">${ speakerMap[speaker].name || speaker }</span></button></div></div></div>++ <!-- Virtual scroll spacer (bottom) -->+ <div :style="{ height: speakerModalSpacerAfter + 'px' }"></div></div><div v-else v-html="highlightedTranscript"></div></div>