Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Add playback speed control (0.5x-3x) to all audio players
Murtaza Nasir476524b8c3d1
diff --git a/static/css/styles.css b/static/css/styles.cssindex a774630e..86e55c5f 100644--- a/static/css/styles.css+++ b/static/css/styles.css@@ -3029,6 +3029,23 @@ body {filter: brightness(1.15);}+/* Playback Speed Control Dropdown */+.speed-dropdown {+ animation: speedDropdownFade 0.12s ease-out;+ width: 52px;+}++@keyframes speedDropdownFade {+ from {+ opacity: 0;+ transform: scale(0.95);+ }+ to {+ opacity: 1;+ transform: scale(1);+ }+}+/* Custom audio player wrapper for better control */.custom-audio-wrapper {position: relative;diff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex 66e990e5..b09d6e80 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -508,11 +508,16 @@ document.addEventListener('DOMContentLoaded', async () => {const audioIsMuted = ref(false);const audioIsLoading = ref(false);const asrEditorAudio = ref(null);+ const playbackRate = ref(1.0);+ const showSpeedMenu = ref(false);+ const playbackSpeeds = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0];+ const speedMenuPosition = ref({});// --- Modal Audio Player State (Independent from main) ---const modalAudioCurrentTime = ref(0);const modalAudioDuration = ref(0);const modalAudioIsPlaying = ref(false);+ const modalPlaybackRate = ref(1.0);// --- Column Resizing State ---const leftColumnWidth = ref(60);@@ -675,7 +680,8 @@ document.addEventListener('DOMContentLoaded', async () => {// Audio PlayerplayerVolume, audioIsPlaying, audioCurrentTime, audioDuration, audioIsMuted, audioIsLoading, asrEditorAudio,- modalAudioCurrentTime, modalAudioDuration, modalAudioIsPlaying,+ modalAudioCurrentTime, modalAudioDuration, modalAudioIsPlaying, modalPlaybackRate,+ playbackRate, showSpeedMenu, playbackSpeeds, speedMenuPosition,// Column ResizingleftColumnWidth, rightColumnWidth, isResizing,diff --git a/static/js/modules/composables/ui.js b/static/js/modules/composables/ui.jsindex 6c8f02bc..367e88b4 100644--- a/static/js/modules/composables/ui.js+++ b/static/js/modules/composables/ui.js@@ -15,7 +15,8 @@ export function useUI(state, utils, processedTranscription) {editingNotes, tempNotesContent, transcriptionViewMode,notesMarkdownEditor, markdownEditorInstance, autoSaveTimer, csrfToken,summaryMarkdownEditor, recordingNotesEditor, recordingMarkdownEditorInstance,- recordingNotes, showDownloadMenu, currentPlayingSegmentIndex, followPlayerMode+ recordingNotes, showDownloadMenu, currentPlayingSegmentIndex, followPlayerMode,+ playbackRate, showSpeedMenu, playbackSpeeds, modalPlaybackRate, speedMenuPosition} = state;const autoSaveDelay = 2000; // 2 seconds@@ -986,6 +987,11 @@ export function useUI(state, utils, processedTranscription) {}}audioIsLoading.value = false;++ // Apply saved playback rate when audio loads+ if (playbackRate.value !== 1) {+ event.target.playbackRate = playbackRate.value;+ }};const handleAudioEnded = () => {@@ -1043,6 +1049,90 @@ export function useUI(state, utils, processedTranscription) {return `${mins}:${secs.toString().padStart(2, '0')}`;};+ // --- Playback Speed Control ---+ const formatPlaybackRate = (rate) => {+ if (rate === 1) return '1x';+ if (rate === Math.floor(rate)) return `${rate}x`;+ return `${rate}x`;+ };++ const setPlaybackRate = (rate) => {+ playbackRate.value = rate;+ localStorage.setItem('playbackRate', rate);++ // Apply to all audio elements+ const audioElements = document.querySelectorAll('audio');+ audioElements.forEach(audio => {+ audio.playbackRate = rate;+ });+ };++ const cyclePlaybackRate = () => {+ const currentIndex = playbackSpeeds.indexOf(playbackRate.value);+ const nextIndex = (currentIndex + 1) % playbackSpeeds.length;+ setPlaybackRate(playbackSpeeds[nextIndex]);+ };++ const cycleModalPlaybackRate = () => {+ const currentIndex = playbackSpeeds.indexOf(modalPlaybackRate.value);+ const nextIndex = (currentIndex + 1) % playbackSpeeds.length;+ modalPlaybackRate.value = playbackSpeeds[nextIndex];++ // Apply to modal audio elements+ const modalAudio = document.querySelector('.speaker-modal-transcript')?.closest('.fixed')?.querySelector('audio') ||+ document.querySelector('[ref="speakerModalAudioRef"]') ||+ document.querySelector('[ref="asrEditorAudioRef"]');+ if (modalAudio) {+ modalAudio.playbackRate = modalPlaybackRate.value;+ }+ };++ const initializePlaybackRate = () => {+ const savedRate = localStorage.getItem('playbackRate');+ if (savedRate) {+ const rate = parseFloat(savedRate);+ if (playbackSpeeds.includes(rate)) {+ playbackRate.value = rate;+ }+ }+ };++ const updateSpeedMenuPosition = (buttonEl) => {+ if (!buttonEl) return;+ const rect = buttonEl.getBoundingClientRect();+ const menuWidth = 52;+ const menuMaxHeight = 160;+ const gap = 4;+ const safeZone = 60; // Account for header/navbar++ // Check available space above and below+ const spaceAbove = rect.top - safeZone;+ const spaceBelow = window.innerHeight - rect.bottom - 8;++ // Decide direction: prefer above, but use below if not enough space+ const showBelow = spaceAbove < menuMaxHeight && spaceBelow > spaceAbove;++ const right = window.innerWidth - rect.right;++ if (showBelow) {+ // Position below the button+ speedMenuPosition.value = {+ right: `${Math.max(8, right)}px`,+ top: `${rect.bottom + gap}px`,+ bottom: 'auto',+ maxHeight: `${Math.min(menuMaxHeight, spaceBelow)}px`+ };+ } else {+ // Position above the button+ speedMenuPosition.value = {+ right: `${Math.max(8, right)}px`,+ bottom: `${window.innerHeight - rect.top + gap}px`,+ top: 'auto',+ maxHeight: `${Math.min(menuMaxHeight, spaceAbove)}px`+ };+ }+ };+const audioProgressPercent = computed(() => {// Use preview position while dragging for smooth UIif (isDraggingProgress.value) {@@ -1525,6 +1615,9 @@ export function useUI(state, utils, processedTranscription) {followPlayerMode.value = savedFollowMode === 'true';}+ // Load saved playback rate+ initializePlaybackRate();+// Watch for recording changes to reset active segment and audio player statewatch(selectedRecording, (newRecording) => {currentPlayingSegmentIndex.value = null;@@ -1586,6 +1679,16 @@ export function useUI(state, utils, processedTranscription) {state.showLanguageMenu.value = false;}}++ // Close speed menu if clicking outside+ if (showSpeedMenu.value) {+ const speedButton = target.closest('[data-speed-toggle]');+ const speedDropdown = target.closest('[data-speed-dropdown]');++ if (!speedButton && !speedDropdown) {+ showSpeedMenu.value = false;+ }+ }});};@@ -1855,6 +1958,12 @@ export function useUI(state, utils, processedTranscription) {audioIsMuted,audioIsLoading,resetAudioPlayerState,+ // Playback speed+ formatPlaybackRate,+ setPlaybackRate,+ cyclePlaybackRate,+ cycleModalPlaybackRate,+ updateSpeedMenuPosition,// Copy functionscopyTranscription,copySummary,diff --git a/static/locales/de.json b/static/locales/de.jsonindex 3e498efd..f12c4866 100644--- a/static/locales/de.json+++ b/static/locales/de.json@@ -1132,6 +1132,7 @@"play": "Abspielen","pause": "Pause","mute": "Stumm",- "unmute": "Ton an"+ "unmute": "Ton an",+ "playbackSpeed": "Wiedergabegeschwindigkeit"}}\ No newline at end of filediff --git a/static/locales/en.json b/static/locales/en.jsonindex a3fbd6bc..0853715f 100644--- a/static/locales/en.json+++ b/static/locales/en.json@@ -1160,6 +1160,7 @@"play": "Play","pause": "Pause","mute": "Mute",- "unmute": "Unmute"+ "unmute": "Unmute",+ "playbackSpeed": "Playback speed"}}\ No newline at end of filediff --git a/static/locales/es.json b/static/locales/es.jsonindex bb16599a..62469d69 100644--- a/static/locales/es.json+++ b/static/locales/es.json@@ -1101,6 +1101,7 @@"play": "Reproducir","pause": "Pausa","mute": "Silenciar",- "unmute": "Activar sonido"+ "unmute": "Activar sonido",+ "playbackSpeed": "Velocidad de reproducción"}}\ No newline at end of filediff --git a/static/locales/fr.json b/static/locales/fr.jsonindex f0d53929..80e6ab97 100644--- a/static/locales/fr.json+++ b/static/locales/fr.json@@ -1101,6 +1101,7 @@"play": "Lecture","pause": "Pause","mute": "Muet",- "unmute": "Activer le son"+ "unmute": "Activer le son",+ "playbackSpeed": "Vitesse de lecture"}}\ No newline at end of filediff --git a/static/locales/ru.json b/static/locales/ru.jsonindex f75cbae5..4e954194 100644--- a/static/locales/ru.json+++ b/static/locales/ru.json@@ -1126,6 +1126,7 @@"play": "Воспроизвести","pause": "Пауза","mute": "Без звука",- "unmute": "Включить звук"+ "unmute": "Включить звук",+ "playbackSpeed": "Скорость воспроизведения"}}diff --git a/static/locales/zh.json b/static/locales/zh.jsonindex ecc996df..0c12ff50 100644--- a/static/locales/zh.json+++ b/static/locales/zh.json@@ -1285,6 +1285,7 @@"play": "播放","pause": "暂停","mute": "静音",- "unmute": "取消静音"+ "unmute": "取消静音",+ "playbackSpeed": "播放速度"}}\ No newline at end of filediff --git a/templates/components/detail/audio-player.html b/templates/components/detail/audio-player.htmlindex 9206f047..e9be9fb2 100644--- a/templates/components/detail/audio-player.html+++ b/templates/components/detail/audio-player.html@@ -55,6 +55,33 @@<span class="text-xs text-[var(--text-muted)] font-mono">${ formatAudioTime(audioDuration) }</span></div>+ <!-- Playback Speed Control -->+ <div class="relative flex-shrink-0">+ <button ref="speedButtonMobile"+ @click="showSpeedMenu = !showSpeedMenu; $nextTick(() => updateSpeedMenuPosition($refs.speedButtonMobile))"+ data-speed-toggle+ class="w-8 h-8 flex items-center justify-center rounded-lg hover:bg-[var(--bg-primary)] text-[var(--text-accent)] hover:opacity-80 transition-all"+ :title="t('tooltips.playbackSpeed') || 'Playback speed'">+ <span class="text-xs font-semibold font-mono">${ formatPlaybackRate(playbackRate) }</span>+ </button>+ <!-- Dropdown menu (teleported to body, fixed positioning) -->+ <Teleport to="body">+ <div v-if="showSpeedMenu" @click.stop+ data-speed-dropdown+ class="fixed bg-[var(--bg-tertiary)] border border-[var(--border-accent)] rounded-md shadow-xl z-[9999] speed-dropdown overflow-y-auto backdrop-blur-sm"+ :style="speedMenuPosition">+ <div class="py-0.5">+ <button v-for="speed in playbackSpeeds" :key="speed"+ @mousedown.prevent="setPlaybackRate(speed); showSpeedMenu = false"+ class="w-full px-2 py-0.5 text-[11px] font-mono text-left hover:bg-[var(--bg-accent-light)] transition-colors"+ :class="speed === playbackRate ? 'text-[var(--text-accent)] font-semibold bg-[var(--bg-accent-light)]' : 'text-[var(--text-primary)]'">+ ${ speed }x+ </button>+ </div>+ </div>+ </Teleport>+ </div>+<!-- Spacer --><div class="flex-1"></div>diff --git a/templates/components/detail/desktop-right-panel.html b/templates/components/detail/desktop-right-panel.htmlindex 75a9d0c7..60c8ccf8 100644--- a/templates/components/detail/desktop-right-panel.html+++ b/templates/components/detail/desktop-right-panel.html@@ -56,6 +56,33 @@<span class="text-xs text-[var(--text-muted)] font-mono">${ formatAudioTime(audioDuration) }</span></div>+ <!-- Playback Speed Control -->+ <div class="relative flex-shrink-0">+ <button ref="speedButtonDesktop"+ @click="showSpeedMenu = !showSpeedMenu; $nextTick(() => updateSpeedMenuPosition($refs.speedButtonDesktop))"+ data-speed-toggle+ class="w-8 h-8 flex items-center justify-center rounded-lg hover:bg-[var(--bg-primary)] text-[var(--text-accent)] hover:opacity-80 transition-all"+ :title="t('tooltips.playbackSpeed') || 'Playback speed'">+ <span class="text-xs font-semibold font-mono">${ formatPlaybackRate(playbackRate) }</span>+ </button>+ <!-- Dropdown menu (teleported to body, fixed positioning) -->+ <Teleport to="body">+ <div v-if="showSpeedMenu" @click.stop+ data-speed-dropdown+ class="fixed bg-[var(--bg-tertiary)] border border-[var(--border-accent)] rounded-md shadow-xl z-[9999] speed-dropdown overflow-y-auto backdrop-blur-sm"+ :style="speedMenuPosition">+ <div class="py-0.5">+ <button v-for="speed in playbackSpeeds" :key="speed"+ @mousedown.prevent="setPlaybackRate(speed); showSpeedMenu = false"+ class="w-full px-2 py-0.5 text-[11px] font-mono text-left hover:bg-[var(--bg-accent-light)] transition-colors"+ :class="speed === playbackRate ? 'text-[var(--text-accent)] font-semibold bg-[var(--bg-accent-light)]' : 'text-[var(--text-primary)]'">+ ${ speed }x+ </button>+ </div>+ </div>+ </Teleport>+ </div>+<!-- Spacer --><div class="flex-1 min-w-0"></div>diff --git a/templates/modals/asr-editor-modal.html b/templates/modals/asr-editor-modal.htmlindex c2f04edd..85366f2b 100644--- a/templates/modals/asr-editor-modal.html+++ b/templates/modals/asr-editor-modal.html@@ -56,6 +56,12 @@@input="(e) => { if ($refs.asrEditorAudioRef) $refs.asrEditorAudioRef.volume = parseFloat(e.target.value); }"class="volume-slider w-20 h-1.5 rounded-full cursor-pointer"></div>+ <!-- Speed Control (compact - tap to cycle) -->+ <button @click="cycleModalPlaybackRate(); if ($refs.asrEditorAudioRef) $refs.asrEditorAudioRef.playbackRate = modalPlaybackRate"+ class="w-8 h-8 flex items-center justify-center rounded hover:bg-[var(--bg-tertiary)] text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-all flex-shrink-0"+ title="Playback speed (tap to change)">+ <span class="text-xs font-semibold font-mono">${ formatPlaybackRate(modalPlaybackRate) }</span>+ </button></div></div>diff --git a/templates/modals/speaker-modal.html b/templates/modals/speaker-modal.htmlindex 8a8f0ae3..9092c344 100644--- a/templates/modals/speaker-modal.html+++ b/templates/modals/speaker-modal.html@@ -171,6 +171,12 @@class="w-7 h-7 flex items-center justify-center rounded hover:bg-[var(--bg-tertiary)] text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-all flex-shrink-0"><i :class="playerVolume === 0 ? 'fas fa-volume-mute' : 'fas fa-volume-up'" class="text-xs"></i></button>+ <!-- Speed Control (compact - tap to cycle) -->+ <button @click="cycleModalPlaybackRate(); if ($refs.speakerModalAudioRef) $refs.speakerModalAudioRef.playbackRate = modalPlaybackRate"+ class="w-7 h-7 flex items-center justify-center rounded hover:bg-[var(--bg-tertiary)] text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-all flex-shrink-0"+ title="Playback speed (tap to change)">+ <span class="text-[10px] font-semibold font-mono">${ formatPlaybackRate(modalPlaybackRate) }</span>+ </button></div></div>diff --git a/templates/share.html b/templates/share.htmlindex 119ea0dc..cec0105e 100644--- a/templates/share.html+++ b/templates/share.html@@ -129,6 +129,26 @@<span class="text-sm text-[var(--text-primary)] font-mono">${ formatAudioTime(audioCurrentTime) }</span><span class="text-xs text-[var(--text-muted)] font-mono">${ formatAudioTime(audioDuration) }</span></div>+ <!-- Playback Speed Control -->+ <div class="relative flex-shrink-0">+ <button @click="showSpeedMenu = !showSpeedMenu"+ class="w-8 h-8 flex items-center justify-center rounded-lg hover:bg-[var(--bg-tertiary)] text-[var(--text-accent)] hover:opacity-80 transition-all"+ title="Playback speed">+ <span class="text-xs font-semibold font-mono">${ formatPlaybackRate(playbackRate) }</span>+ </button>+ <!-- Dropdown menu (opens upward) -->+ <div v-if="showSpeedMenu" @click.stop+ class="absolute bottom-full mb-1 left-1/2 -translate-x-1/2 bg-[var(--bg-tertiary)] border border-[var(--border-accent)] rounded-md shadow-xl z-50 speed-dropdown backdrop-blur-sm">+ <div class="py-0.5 max-h-40 overflow-y-auto">+ <button v-for="speed in playbackSpeeds" :key="speed"+ @mousedown.prevent="setPlaybackRate(speed); showSpeedMenu = false"+ class="w-full px-2 py-0.5 text-[11px] font-mono text-left hover:bg-[var(--bg-accent-light)] transition-colors"+ :class="speed === playbackRate ? 'text-[var(--text-accent)] font-semibold bg-[var(--bg-accent-light)]' : 'text-[var(--text-primary)]'">+ ${ speed }x+ </button>+ </div>+ </div>+ </div><!-- Progress Bar --><div class="flex-1 h-2 bg-[var(--bg-tertiary)] rounded-full cursor-pointer group relative"@click="(e) => { const rect = e.currentTarget.getBoundingClientRect(); seekAudioByPercent(((e.clientX - rect.left) / rect.width) * 100); }">@@ -353,6 +373,11 @@const audioIsMuted = ref(false);const playerVolume = ref(1.0);+ // Playback speed state+ const playbackRate = ref(1.0);+ const showSpeedMenu = ref(false);+ const playbackSpeeds = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0];+// Computed property for progress percentageconst audioProgressPercent = computed(() => {if (!audioDuration.value) return 0;@@ -388,6 +413,10 @@audioDuration.value = duration;}}+ // Apply saved playback rate when audio loads+ if (playbackRate.value !== 1) {+ event.target.playbackRate = playbackRate.value;+ }}function handleAudioDurationChange(event) {@@ -436,6 +465,29 @@audioPlayer.value.currentTime = time;}+ // Playback speed functions+ function formatPlaybackRate(rate) {+ if (rate === 1) return '1x';+ return `${rate}x`;+ }++ function setPlaybackRate(rate) {+ playbackRate.value = rate;+ localStorage.setItem('playbackRate', rate);+ if (audioPlayer.value) {+ audioPlayer.value.playbackRate = rate;+ }+ }++ // Initialize playback rate from localStorage+ const savedRate = localStorage.getItem('playbackRate');+ if (savedRate) {+ const rate = parseFloat(savedRate);+ if (playbackSpeeds.includes(rate)) {+ playbackRate.value = rate;+ }+ }+const processedTranscription = computed(() => {if (!recording.value?.transcription) {return { hasDialogue: false, content: '', speakers: [], simpleSegments: [], bubbleRows: [] };@@ -663,7 +715,13 @@toggleAudioPlayback,toggleAudioMute,setAudioVolume,- seekAudioByPercent+ seekAudioByPercent,+ // Playback speed+ playbackRate,+ showSpeedMenu,+ playbackSpeeds,+ formatPlaybackRate,+ setPlaybackRate};}});