Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Speaker modal: stage per-line speaker/text edits until Save; fix one-change-hits-many-lines
Murtaza Nasir1f4f76782425
diff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex 5972bb00..72525932 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -2037,6 +2037,12 @@ document.addEventListener('DOMContentLoaded', async () => {const isNewSpeaker = segment.speakerId !== lastSpeakerId;processedSimpleSegments.push({...segment,+ // The true index into the raw transcription array.+ // The speaker modal MUST use this (not the v-for+ // loop index) for change-speaker / edit-text so the+ // edit hits the exact segment — matches the public+ // release and avoids v-memo/index drift.+ _originalIndex: idx,showSpeaker: isNewSpeaker});if (isNewSpeaker) {diff --git a/static/js/modules/composables/speakers.js b/static/js/modules/composables/speakers.jsindex a9a1009f..8d164253 100644--- a/static/js/modules/composables/speakers.js+++ b/static/js/modules/composables/speakers.js@@ -28,6 +28,15 @@ export function useSpeakers(state, utils, processedTranscription) {// Current speaker highlight statelet currentSpeakerId = null;+ // Snapshot of the recording's transcription taken when the modal opens.+ // Per-line speaker/text edits are now STAGED in memory (changeSpeaker /+ // saveEditedText mutate selectedRecording.transcription for live preview+ // but don't persist). If the user Cancels with unsaved staged edits, we+ // restore this snapshot so the cancelled edits don't leak into the+ // detail view. On a real save the staged flag is cleared first so no+ // revert happens.+ let originalTranscriptionSnapshot = null;+// Number of speaker colors available in CSS (must match styles.css and app.modular.js)const SPEAKER_COLOR_COUNT = 16;@@ -64,6 +73,11 @@ export function useSpeakers(state, utils, processedTranscription) {// Pause outer audio player to avoid conflicts with modal's playerpauseOuterAudioPlayer();+ // Snapshot the committed transcription and clear any stale staged+ // edits so this modal session starts from a clean, saved state.+ originalTranscriptionSnapshot = selectedRecording.value.transcription || null;+ editedTranscriptData.value = null;+// Clear any existing speaker map data firstspeakerMap.value = {};speakerDisplayMap.value = {};@@ -177,6 +191,16 @@ export function useSpeakers(state, utils, processedTranscription) {utils.resetModalAudioState();}+ // If the modal is closing with UNSAVED staged per-line edits (the+ // user hit Cancel/X, not Save), discard them by restoring the+ // snapshot taken on open. A real save clears editedTranscriptData+ // before calling this, so saved edits are never reverted.+ if (editedTranscriptData.value && originalTranscriptionSnapshot != null && selectedRecording.value) {+ selectedRecording.value.transcription = originalTranscriptionSnapshot;+ }+ editedTranscriptData.value = null;+ originalTranscriptionSnapshot = null;+showSpeakerModal.value = false;showAutoIdDropdown.value = false;highlightedSpeaker.value = null;@@ -262,6 +286,10 @@ export function useSpeakers(state, utils, processedTranscription) {const data = await response.json();if (!response.ok) throw new Error(data.error || 'Failed to update transcript');+ // The edits are now persisted on the server — clear the staged+ // flag BEFORE closing so closeSpeakerModal doesn't mistake this+ // for a Cancel and revert the just-saved changes.+ editedTranscriptData.value = null;closeSpeakerModal();// If summary regeneration was requested, update status immediately@@ -1139,23 +1167,20 @@ export function useSpeakers(state, utils, processedTranscription) {editedText.value = '';};- const saveEditedText = async () => {+ const saveEditedText = () => {if (editingSegmentIndex.value === null || !selectedRecording.value?.transcription) return;try {const transcriptionData = JSON.parse(selectedRecording.value.transcription);if (transcriptionData && Array.isArray(transcriptionData) && transcriptionData[editingSegmentIndex.value]) {transcriptionData[editingSegmentIndex.value].sentence = editedText.value;- editedTranscriptData.value = transcriptionData;- // Update the recording's transcription temporarily for UI update+ // Stage in memory only (same as changeSpeaker) — persisted on+ // "Save Names". No surprise live save.+ editedTranscriptData.value = transcriptionData;selectedRecording.value.transcription = JSON.stringify(transcriptionData);closeEditTextModal();-- // Immediately persist the change- showToast(t('help.savingProgress'), 'fa-spinner fa-spin');- await saveTranscriptImmediately(transcriptionData);}} catch (e) {console.error('Error saving text:', e);@@ -1171,23 +1196,32 @@ export function useSpeakers(state, utils, processedTranscription) {editingSpeakerIndex.value = editingSpeakerIndex.value === segmentIndex ? null : segmentIndex;};- const changeSpeaker = async (segmentIndex, newSpeakerId) => {+ const changeSpeaker = (segmentIndex, newSpeakerId) => {if (!selectedRecording.value?.transcription) return;try {const transcriptionData = JSON.parse(selectedRecording.value.transcription);if (transcriptionData && Array.isArray(transcriptionData) && transcriptionData[segmentIndex]) {transcriptionData[segmentIndex].speaker = newSpeakerId;++ // STAGE the change in memory only. It is persisted when the+ // user clicks "Save Names" (saveSpeakerNames sees+ // editedTranscriptData and calls saveTranscriptEdits).+ //+ // We deliberately do NOT save immediately here. The old+ // behaviour called saveTranscriptImmediately on every single+ // per-line change, which (a) saved without the user asking+ // (the surprise "changes saved" toast) and (b) re-sent the+ // full speaker_map, which the backend applies by renaming+ // EVERY segment matching a mapped speaker — so changing one+ // line silently rewrote all the other lines of that speaker.editedTranscriptData.value = transcriptionData;- // Update the recording's transcription temporarily for UI update+ // Update the recording's transcription in memory so the+ // modal reflects the change live (still unsaved).selectedRecording.value.transcription = JSON.stringify(transcriptionData);editingSpeakerIndex.value = null;-- // Immediately persist the change- showToast(t('help.savingProgress'), 'fa-spinner fa-spin');- await saveTranscriptImmediately(transcriptionData);}} catch (e) {console.error('Error changing speaker:', e);diff --git a/templates/modals/speaker-modal.html b/templates/modals/speaker-modal.htmlindex 5d5c51d1..414c2846 100644--- a/templates/modals/speaker-modal.html+++ b/templates/modals/speaker-modal.html@@ -289,12 +289,12 @@rendering regressions. v-memo per row stopsVue from re-rendering unrelated rows whenone row's data changes. -->- <div v-for="(segment, idx) in processedTranscription.simpleSegments"- :key="segment.startTime + '-' + idx"- v-memo="[idx, segment.speakerId, segment.speaker, segment.sentence, highlightedSpeaker === segment.speakerId, editingSpeakerIndex === idx]"+ <div v-for="segment in processedTranscription.simpleSegments"+ :key="segment._originalIndex"+ v-memo="[segment._originalIndex, segment.speakerId, segment.speaker, segment.sentence, highlightedSpeaker === segment.speakerId, editingSpeakerIndex === segment._originalIndex]"class="speaker-segment group relative":data-start-time="segment.startTime"- :data-segment-index="idx">+ :data-segment-index="segment._originalIndex"><div class="flex items-start gap-2"><span :class="[segment.color, 'speaker-tag', { 'speaker-highlight': highlightedSpeaker === segment.speakerId }]":data-speaker-id="segment.speakerId"@@ -302,15 +302,15 @@:title="segment.speaker">${ segment.speaker }</span><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><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(idx)" class="btn btn--icon btn--sm" title="Change speaker">+ <button @click.stop="openSpeakerChangeDropdown(segment._originalIndex)" class="btn btn--icon btn--sm" title="Change speaker"><i class="fas fa-user-edit text-[10px]"></i></button>- <button @click.stop="openEditTextModal(idx)" class="btn btn--icon btn--sm" title="Edit text">+ <button @click.stop="openEditTextModal(segment._originalIndex)" class="btn btn--icon btn--sm" title="Edit text"><i class="fas fa-edit text-[10px]"></i></button></span></div>- <div v-if="editingSpeakerIndex === idx"+ <div v-if="editingSpeakerIndex === segment._originalIndex"@click.stopclass="surface-raised"style="margin-top: var(--sp-2); padding: var(--sp-2);">@@ -318,7 +318,7 @@<div class="flex flex-wrap gap-1"><button v-for="speaker in modalSpeakers":key="speaker"- @click="changeSpeaker(idx, 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-tertiary)]"><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>