Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Add custom audio player to modals and share page with proper scoping

Murtaza Nasir9453738b99a8
diff --git a/static/js/modules/composables/speakers.js b/static/js/modules/composables/speakers.js
index 544535db..6cfe4d88 100644
--- a/static/js/modules/composables/speakers.js
+++ b/static/js/modules/composables/speakers.js
@@ -128,6 +128,12 @@ export function useSpeakers(state, utils, processedTranscription) {
};
const closeSpeakerModal = () => {
+ // Pause any playing modal audio before closing
+ const modalAudio = document.querySelector('.fixed.z-50 audio');
+ if (modalAudio) {
+ modalAudio.pause();
+ }
+
showSpeakerModal.value = false;
highlightedSpeaker.value = null;
// Clear the speaker map to prevent stale data from persisting
diff --git a/static/js/modules/composables/transcription.js b/static/js/modules/composables/transcription.js
index 09dba56e..59ebbff6 100644
--- a/static/js/modules/composables/transcription.js
+++ b/static/js/modules/composables/transcription.js
@@ -80,6 +80,12 @@ export function useTranscription(state, utils) {
};
const closeAsrEditorModal = () => {
+ // Pause any playing modal audio before closing
+ const modalAudio = document.querySelector('.fixed.z-50 audio');
+ if (modalAudio) {
+ modalAudio.pause();
+ }
+
showAsrEditorModal.value = false;
editingSegments.value = [];
};
diff --git a/static/js/modules/composables/ui.js b/static/js/modules/composables/ui.js
index 278e3f78..3fb6fa6c 100644
--- a/static/js/modules/composables/ui.js
+++ b/static/js/modules/composables/ui.js
@@ -818,7 +818,12 @@ export function useUI(state, utils, processedTranscription) {
// --- Custom Audio Player Controls ---
const getAudioElement = () => {
- // Try to find audio in right column (desktop) or detail view (mobile)
+ // First check for audio in visible modals (z-50 class) - these take priority
+ const modalAudio = document.querySelector('.fixed.z-50 audio');
+ if (modalAudio) {
+ return modalAudio;
+ }
+ // Fall back to main player in right column (desktop) or detail view (mobile)
return document.querySelector('#rightMainColumn audio') ||
document.querySelector('.detail-view audio') ||
document.querySelector('audio[ref="audioPlayerElement"]') ||
@@ -1679,6 +1684,7 @@ export function useUI(state, utils, processedTranscription) {
audioDuration,
audioIsMuted,
audioIsLoading,
+ resetAudioPlayerState,
// Copy functions
copyTranscription,
copySummary,
diff --git a/templates/modals/asr-editor-modal.html b/templates/modals/asr-editor-modal.html
index c42a66a3..bcd12642 100644
--- a/templates/modals/asr-editor-modal.html
+++ b/templates/modals/asr-editor-modal.html
@@ -10,16 +10,53 @@
<!-- Audio Player Section -->
<div class="px-6 py-4 border-b border-[var(--border-primary)] flex-shrink-0">
- <div class="audio-player-container">
- <!-- Show message if audio has been deleted -->
- <div v-if="selectedRecording.audio_deleted_at"
- class="bg-[var(--bg-tertiary)] border border-[var(--border-primary)] text-[var(--text-secondary)] px-4 py-3 rounded-lg flex items-center gap-2 text-sm">
- <i class="fas fa-info-circle"></i>
- <span v-text="t('help.audioDeletedMessage')"></span>
- </div>
- <audio v-else ref="asrEditorAudio" controls class="w-full" :key="'asr-editor-' + selectedRecording.id" :src="'/audio/' + selectedRecording.id" :volume="playerVolume" @volumechange="onPlayerVolumeChange">
- Your browser does not support the audio element.
+ <!-- Show message if audio has been deleted -->
+ <div v-if="selectedRecording.audio_deleted_at"
+ class="bg-[var(--bg-tertiary)] border border-[var(--border-primary)] text-[var(--text-secondary)] px-4 py-3 rounded-lg flex items-center gap-2 text-sm">
+ <i class="fas fa-info-circle"></i>
+ <span v-text="t('help.audioDeletedMessage')"></span>
+ </div>
+ <!-- Custom Audio Player -->
+ <div v-else class="flex items-center gap-3">
+ <audio ref="asrEditorAudio" class="hidden"
+ :key="'asr-editor-' + selectedRecording.id"
+ :src="'/audio/' + selectedRecording.id"
+ :volume="playerVolume"
+ @play="handleAudioPlayPause"
+ @pause="handleAudioPlayPause"
+ @timeupdate="handleCustomAudioTimeUpdate"
+ @loadedmetadata="handleAudioLoadedMetadata"
+ @ended="handleAudioEnded"
+ @volumechange="onPlayerVolumeChange">
</audio>
+ <!-- Play/Pause -->
+ <button @click="toggleAudioPlayback"
+ class="w-10 h-10 flex items-center justify-center rounded-full bg-[var(--bg-accent)] hover:bg-[var(--bg-accent-hover)] text-white transition-all flex-shrink-0 shadow-sm"
+ :title="audioIsPlaying ? 'Pause' : 'Play'">
+ <i :class="audioIsPlaying ? 'fas fa-pause' : 'fas fa-play'" class="text-sm" :style="!audioIsPlaying ? 'margin-left: 2px' : ''"></i>
+ </button>
+ <!-- Time -->
+ <div class="flex flex-col items-end flex-shrink-0 leading-none">
+ <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>
+ <!-- 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); }">
+ <div class="h-full bg-[var(--bg-accent)] rounded-full transition-all duration-100"
+ :style="{ width: audioProgressPercent + '%' }">
+ </div>
+ </div>
+ <!-- Volume -->
+ <div class="flex items-center gap-2 flex-shrink-0">
+ <button @click="toggleAudioMute"
+ 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">
+ <i :class="audioIsMuted || playerVolume === 0 ? 'fas fa-volume-mute' : 'fas fa-volume-up'" class="text-sm"></i>
+ </button>
+ <input type="range" min="0" max="1" step="0.05" :value="playerVolume"
+ @input="(e) => setAudioVolume(parseFloat(e.target.value))"
+ class="volume-slider w-20 h-1.5 rounded-full cursor-pointer">
+ </div>
</div>
</div>
diff --git a/templates/modals/speaker-modal.html b/templates/modals/speaker-modal.html
index 6ed579ef..53f205dd 100644
--- a/templates/modals/speaker-modal.html
+++ b/templates/modals/speaker-modal.html
@@ -130,16 +130,48 @@
:class="{ 'hidden lg:flex': speakerModalTab !== 'transcript', 'flex-1': speakerModalTab === 'transcript' }">
<!-- Audio Player Section -->
<div class="mb-2 sm:mb-4 flex-shrink-0">
- <div class="audio-player-container">
- <!-- Show message if audio has been deleted -->
- <div v-if="selectedRecording.audio_deleted_at"
- class="bg-[var(--bg-tertiary)] border border-[var(--border-primary)] text-[var(--text-secondary)] px-3 py-2 rounded-md flex items-center gap-2 text-xs">
- <i class="fas fa-info-circle"></i>
- <span v-text="t('help.audioDeletedMessage')"></span>
- </div>
- <audio v-else controls class="w-full speaker-modal-transcript h-10" :key="selectedRecording.id" :src="'/audio/' + selectedRecording.id" :volume="playerVolume" @volumechange="onPlayerVolumeChange">
- Your browser does not support the audio element.
+ <!-- Show message if audio has been deleted -->
+ <div v-if="selectedRecording.audio_deleted_at"
+ class="text-[var(--text-muted)] text-xs flex items-center gap-2">
+ <i class="fas fa-info-circle"></i>
+ <span v-text="t('help.audioDeletedMessage')"></span>
+ </div>
+ <!-- Custom Audio Player -->
+ <div v-else class="flex items-center gap-2">
+ <audio class="hidden speaker-modal-transcript"
+ :key="selectedRecording.id"
+ :src="'/audio/' + selectedRecording.id"
+ :volume="playerVolume"
+ @play="handleAudioPlayPause"
+ @pause="handleAudioPlayPause"
+ @timeupdate="handleCustomAudioTimeUpdate"
+ @loadedmetadata="handleAudioLoadedMetadata"
+ @ended="handleAudioEnded"
+ @volumechange="onPlayerVolumeChange">
</audio>
+ <!-- Play/Pause -->
+ <button @click="toggleAudioPlayback"
+ class="w-8 h-8 flex items-center justify-center rounded-full bg-[var(--bg-accent)] hover:bg-[var(--bg-accent-hover)] text-white transition-all flex-shrink-0 shadow-sm"
+ :title="audioIsPlaying ? 'Pause' : 'Play'">
+ <i :class="audioIsPlaying ? 'fas fa-pause' : 'fas fa-play'" class="text-xs" :style="!audioIsPlaying ? 'margin-left: 1px' : ''"></i>
+ </button>
+ <!-- Time -->
+ <div class="flex flex-col items-end flex-shrink-0 leading-none">
+ <span class="text-xs text-[var(--text-primary)] font-mono">${ formatAudioTime(audioCurrentTime) }</span>
+ <span class="text-[10px] text-[var(--text-muted)] font-mono">${ formatAudioTime(audioDuration) }</span>
+ </div>
+ <!-- Progress Bar -->
+ <div class="flex-1 h-1.5 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); }">
+ <div class="h-full bg-[var(--bg-accent)] rounded-full transition-all duration-100"
+ :style="{ width: audioProgressPercent + '%' }">
+ </div>
+ </div>
+ <!-- Volume -->
+ <button @click="toggleAudioMute"
+ 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="audioIsMuted || playerVolume === 0 ? 'fas fa-volume-mute' : 'fas fa-volume-up'" class="text-xs"></i>
+ </button>
</div>
</div>
diff --git a/templates/share.html b/templates/share.html
index 2227dc62..8e6c8e3c 100644
--- a/templates/share.html
+++ b/templates/share.html
@@ -107,9 +107,44 @@
<i class="fas fa-info-circle"></i>
<span>Audio file has been archived and is no longer available for playback.</span>
</div>
- <!-- Show audio player if audio is available -->
- <div v-else class="audio-player-container">
- <audio controls class="w-full" :src="'/share/audio/' + recording.public_id" ref="audioPlayer"></audio>
+ <!-- Custom Audio Player -->
+ <div v-else class="flex items-center gap-3">
+ <audio ref="audioPlayer" class="hidden"
+ :src="'/share/audio/' + recording.public_id"
+ @play="handleAudioPlayPause"
+ @pause="handleAudioPlayPause"
+ @timeupdate="handleCustomAudioTimeUpdate"
+ @loadedmetadata="handleAudioLoadedMetadata"
+ @ended="handleAudioEnded">
+ </audio>
+ <!-- Play/Pause -->
+ <button @click="toggleAudioPlayback"
+ class="w-10 h-10 flex items-center justify-center rounded-full bg-[var(--bg-accent)] hover:bg-[var(--bg-accent-hover)] text-white transition-all flex-shrink-0 shadow-sm"
+ :title="audioIsPlaying ? 'Pause' : 'Play'">
+ <i :class="audioIsPlaying ? 'fas fa-pause' : 'fas fa-play'" class="text-sm" :style="!audioIsPlaying ? 'margin-left: 2px' : ''"></i>
+ </button>
+ <!-- Time -->
+ <div class="flex flex-col items-end flex-shrink-0 leading-none">
+ <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>
+ <!-- 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); }">
+ <div class="h-full bg-[var(--bg-accent)] rounded-full transition-all duration-100"
+ :style="{ width: audioProgressPercent + '%' }">
+ </div>
+ </div>
+ <!-- Volume -->
+ <div class="flex items-center gap-2 flex-shrink-0">
+ <button @click="toggleAudioMute"
+ 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">
+ <i :class="audioIsMuted || playerVolume === 0 ? 'fas fa-volume-mute' : 'fas fa-volume-up'" class="text-sm"></i>
+ </button>
+ <input type="range" min="0" max="1" step="0.05" :value="playerVolume"
+ @input="(e) => setAudioVolume(parseFloat(e.target.value))"
+ class="volume-slider w-20 h-1.5 rounded-full cursor-pointer">
+ </div>
</div>
</div>
</div>
@@ -309,6 +344,80 @@
const legendExpanded = ref(false);
const isDarkMode = ref(document.documentElement.classList.contains('dark'));
+ // Custom audio player state
+ const audioIsPlaying = ref(false);
+ const audioCurrentTime = ref(0);
+ const audioDuration = ref(0);
+ const audioIsMuted = ref(false);
+ const playerVolume = ref(1.0);
+
+ // Computed property for progress percentage
+ const audioProgressPercent = computed(() => {
+ if (!audioDuration.value) return 0;
+ return (audioCurrentTime.value / audioDuration.value) * 100;
+ });
+
+ // Format time as m:ss or h:mm:ss
+ function formatAudioTime(seconds) {
+ if (!seconds || isNaN(seconds)) return '0:00';
+ const hours = Math.floor(seconds / 3600);
+ const mins = Math.floor((seconds % 3600) / 60);
+ const secs = Math.floor(seconds % 60);
+ if (hours > 0) {
+ return `${hours}:${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
+ }
+ return `${mins}:${secs.toString().padStart(2, '0')}`;
+ }
+
+ // Audio event handlers
+ function handleAudioPlayPause(event) {
+ audioIsPlaying.value = !event.target.paused;
+ }
+
+ function handleCustomAudioTimeUpdate(event) {
+ audioCurrentTime.value = event.target.currentTime;
+ }
+
+ function handleAudioLoadedMetadata(event) {
+ audioDuration.value = event.target.duration;
+ }
+
+ function handleAudioEnded() {
+ audioIsPlaying.value = false;
+ }
+
+ // Audio control functions
+ function toggleAudioPlayback() {
+ if (!audioPlayer.value) return;
+ if (audioPlayer.value.paused) {
+ audioPlayer.value.play();
+ } else {
+ audioPlayer.value.pause();
+ }
+ }
+
+ function toggleAudioMute() {
+ if (!audioPlayer.value) return;
+ audioPlayer.value.muted = !audioPlayer.value.muted;
+ audioIsMuted.value = audioPlayer.value.muted;
+ }
+
+ function setAudioVolume(value) {
+ if (!audioPlayer.value) return;
+ playerVolume.value = value;
+ audioPlayer.value.volume = value;
+ if (value > 0 && audioIsMuted.value) {
+ audioPlayer.value.muted = false;
+ audioIsMuted.value = false;
+ }
+ }
+
+ function seekAudioByPercent(percent) {
+ if (!audioPlayer.value || !audioDuration.value) return;
+ const time = (percent / 100) * audioDuration.value;
+ audioPlayer.value.currentTime = time;
+ }
+
const processedTranscription = computed(() => {
if (!recording.value?.transcription) {
return { hasDialogue: false, content: '', speakers: [], simpleSegments: [], bubbleRows: [] };
@@ -519,7 +628,23 @@
copyTranscript,
copySummary,
copyNotes,
- toggleDarkMode
+ toggleDarkMode,
+ // Custom audio player
+ audioIsPlaying,
+ audioCurrentTime,
+ audioDuration,
+ audioIsMuted,
+ playerVolume,
+ audioProgressPercent,
+ formatAudioTime,
+ handleAudioPlayPause,
+ handleCustomAudioTimeUpdate,
+ handleAudioLoadedMetadata,
+ handleAudioEnded,
+ toggleAudioPlayback,
+ toggleAudioMute,
+ setAudioVolume,
+ seekAudioByPercent
};
}
});