Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Gate merged-recording playback until its audio is stitched and remove deleted originals from the list once the merge completes
Murtaza Nasir4f6264c4957e
diff --git a/src/api/recordings.py b/src/api/recordings.pyindex cff24fee..87ae7288 100644--- a/src/api/recordings.py+++ b/src/api/recordings.py@@ -3623,8 +3623,12 @@ def get_recording_status_only(recording_id):if not has_recording_access(recording, current_user):return jsonify({'error': 'You do not have permission to view this recording'}), 403- # Return only the status field- return jsonify({'status': recording.status})+ # Return the status plus audio_ready so pollers can enable playback the+ # moment a merge/stitch finishes writing the audio file (#323).+ return jsonify({+ 'status': recording.status,+ 'audio_ready': bool(recording.audio_path) and recording.audio_deleted_at is None,+ })except Exception as e:current_app.logger.error(f"Error fetching status for recording {recording_id}: {e}", exc_info=True)return jsonify({'error': 'An unexpected error occurred.'}), 500diff --git a/src/models/recording.py b/src/models/recording.pyindex 195a8c57..c0a1562d 100644--- a/src/models/recording.py+++ b/src/models/recording.py@@ -350,6 +350,10 @@ class Recording(db.Model):'is_highlighted': self.is_highlighted,'audio_deleted_at': self.audio_deleted_at.isoformat() if self.audio_deleted_at else None,'audio_available': self.audio_deleted_at is None,+ # True only when a playable audio file actually exists yet. A merge+ # (issue #323) creates the row before its audio is stitched, so the+ # UI uses this to keep the play button disabled until the file lands.+ 'audio_ready': bool(self.audio_path) and self.audio_deleted_at is None,'deletion_exempt': self.deletion_exempt,'folder_id': folder_id_ser,'folder': folder_ser,diff --git a/static/js/modules/composables/bulk-operations.js b/static/js/modules/composables/bulk-operations.jsindex 7532f046..728bc2ea 100644--- a/static/js/modules/composables/bulk-operations.js+++ b/static/js/modules/composables/bulk-operations.js@@ -297,6 +297,10 @@ export function useBulkOperations({const orderedIds = mergeOrderedList.value.map(r => r.id);if (orderedIds.length < 2) return;+ // Capture the delete choice now — the modal resets it when reopened, and+ // the removal runs seconds later once the merge audio is ready.+ const shouldDeleteOriginals = mergeDeleteOriginals.value;+mergeInProgress.value = true;bulkActionInProgress.value = true;@@ -321,14 +325,26 @@ export function useBulkOperations({}// The audio concat runs on a worker; originals are deleted there- // only after it succeeds, so we do NOT remove them optimistically.- // They disappear on the next recordings refresh if delete was chosen.-- // Surface the new merged recording immediately (in PROCESSING).+ // only after it succeeds. We do NOT remove them optimistically —+ // instead we wait for the poll to report the merged audio is ready+ // (which happens right after the concat + original-deletion), then+ // drop them from the list. If the merge fails, the poll never fires+ // onAudioReady, so the originals correctly stay put.if (data.recording) {+ const mergedId = data.recording.id;recordings.value.unshift(data.recording);if (startReprocessingPoll) {- startReprocessingPoll(data.recording.id);+ startReprocessingPoll(mergedId, {+ onAudioReady: () => {+ if (!shouldDeleteOriginals) return;+ const removed = new Set(orderedIds);+ recordings.value = recordings.value.filter(r => !removed.has(r.id));+ // If a now-deleted original was open, switch to the merged one.+ if (selectedRecording.value && removed.has(selectedRecording.value.id)) {+ selectedRecording.value = recordings.value.find(r => r.id === mergedId) || null;+ }+ }+ });}}diff --git a/static/js/modules/composables/reprocess.js b/static/js/modules/composables/reprocess.jsindex e3741a48..fbc5e2e6 100644--- a/static/js/modules/composables/reprocess.js+++ b/static/js/modules/composables/reprocess.js@@ -383,12 +383,16 @@ export function useReprocess(state, utils) {// Progress Polling// =========================================- const startReprocessingPoll = (recordingId) => {+ const startReprocessingPoll = (recordingId, options = {}) => {// Stop existing poll if anystopReprocessingPoll(recordingId);// Track if we've already fetched full data for SUMMARIZING statuslet hasFetchedForSummarizing = false;+ // Fire options.onAudioReady exactly once, when the recording's audio+ // first becomes playable (used by merge to remove deleted originals and+ // enable the play button — see bulk-operations.js).+ let audioReadyFired = false;const pollInterval = setInterval(async () => {try {@@ -398,14 +402,16 @@ export function useReprocess(state, utils) {const statusData = await response.json();- // Update status in recordings list+ // Update status (and audio_ready, when the endpoint reports it)+ // in the recordings list.const index = recordings.value.findIndex(r => r.id === recordingId);if (index !== -1) {// Create new object to ensure Vue reactivityrecordings.value[index] = {...recordings.value[index],- status: statusData.status+ status: statusData.status,+ ...(statusData.audio_ready !== undefined ? { audio_ready: statusData.audio_ready } : {})};}@@ -413,10 +419,19 @@ export function useReprocess(state, utils) {if (selectedRecording.value?.id === recordingId) {selectedRecording.value = {...selectedRecording.value,- status: statusData.status+ status: statusData.status,+ ...(statusData.audio_ready !== undefined ? { audio_ready: statusData.audio_ready } : {})};}+ // One-shot callback when audio first becomes playable.+ if (!audioReadyFired && statusData.audio_ready === true) {+ audioReadyFired = true;+ if (typeof options.onAudioReady === 'function') {+ try { options.onAudioReady(); } catch (e) { console.error('onAudioReady error:', e); }+ }+ }+// Check if summarization has started (fetch transcript) or processing is completeif (statusData.status === 'SUMMARIZING' || statusData.status === 'COMPLETED') {// Only fetch once when status first becomes SUMMARIZINGdiff --git a/static/js/modules/composables/ui.js b/static/js/modules/composables/ui.jsindex d492a15b..cdf37ee0 100644--- a/static/js/modules/composables/ui.js+++ b/static/js/modules/composables/ui.js@@ -1013,11 +1013,21 @@ export function useUI(state, utils, processedTranscription) {};const toggleAudioPlayback = () => {+ // A merged recording exists before its audio is stitched; playing it+ // then throws a media error. Block until the file is ready (#323).+ if (selectedRecording.value && selectedRecording.value.audio_ready === false) {+ showToast(t('mergeRecordings.audioPreparing'), 'fa-hourglass-half');+ return;+ }+const audio = getAudioElement();if (!audio) return;if (audio.paused) {- audio.play();+ // Swallow the play() rejection so a transient/unsupported media+ // state does not surface as an uncaught DOMException in the console.+ const p = audio.play();+ if (p && typeof p.catch === 'function') p.catch(() => {});} else {audio.pause();}diff --git a/static/locales/de.json b/static/locales/de.jsonindex 93db2d71..f6880bf4 100644--- a/static/locales/de.json+++ b/static/locales/de.json@@ -1875,6 +1875,7 @@"reprocessNote": "Das kombinierte Audio wird erneut transkribiert und zusammengefasst, um eine durchgehende Transkription und Zusammenfassung zu erstellen.","merging": "Wird zusammengeführt…","confirm": "Zusammenführen",- "videoNote": "Diese Aufnahmen enthalten Video. Beim Zusammenführen wird nur der Ton kombiniert; die zusammengeführte Aufnahme enthält kein Video."+ "videoNote": "Diese Aufnahmen enthalten Video. Beim Zusammenführen wird nur der Ton kombiniert; die zusammengeführte Aufnahme enthält kein Video.",+ "audioPreparing": "Der Ton wird noch vorbereitet. Er ist in Kürze abspielbar."}}\ No newline at end of filediff --git a/static/locales/en.json b/static/locales/en.jsonindex f1d74a8b..c0cb8769 100644--- a/static/locales/en.json+++ b/static/locales/en.json@@ -1875,6 +1875,7 @@"reprocessNote": "The combined audio will be transcribed and summarized again to produce one continuous transcript and summary.","merging": "Merging…","confirm": "Merge recordings",- "videoNote": "These recordings include video. Merging combines the audio only; the merged recording will not have video."+ "videoNote": "These recordings include video. Merging combines the audio only; the merged recording will not have video.",+ "audioPreparing": "Audio is still being prepared. It will be playable in a moment."}}\ No newline at end of filediff --git a/static/locales/es.json b/static/locales/es.jsonindex 2c2ba486..2d971b9e 100644--- a/static/locales/es.json+++ b/static/locales/es.json@@ -1875,6 +1875,7 @@"reprocessNote": "El audio combinado se transcribirá y resumirá de nuevo para producir una transcripción y un resumen continuos.","merging": "Combinando…","confirm": "Combinar",- "videoNote": "Estas grabaciones incluyen vídeo. La combinación une solo el audio; la grabación combinada no tendrá vídeo."+ "videoNote": "Estas grabaciones incluyen vídeo. La combinación une solo el audio; la grabación combinada no tendrá vídeo.",+ "audioPreparing": "El audio aún se está preparando. Podrás reproducirlo en un momento."}}\ No newline at end of filediff --git a/static/locales/fr.json b/static/locales/fr.jsonindex 26f49ce1..8806a012 100644--- a/static/locales/fr.json+++ b/static/locales/fr.json@@ -1875,6 +1875,7 @@"reprocessNote": "L'audio combiné sera de nouveau transcrit et résumé afin de produire une transcription et un résumé continus.","merging": "Fusion…","confirm": "Fusionner",- "videoNote": "Ces enregistrements contiennent de la vidéo. La fusion ne combine que l'audio ; l'enregistrement fusionné n'aura pas de vidéo."+ "videoNote": "Ces enregistrements contiennent de la vidéo. La fusion ne combine que l'audio ; l'enregistrement fusionné n'aura pas de vidéo.",+ "audioPreparing": "L'audio est en cours de préparation. Il sera lisible dans un instant."}}\ No newline at end of filediff --git a/static/locales/pt-BR.json b/static/locales/pt-BR.jsonindex 93cdc6d5..1c43c665 100644--- a/static/locales/pt-BR.json+++ b/static/locales/pt-BR.json@@ -1875,6 +1875,7 @@"reprocessNote": "O áudio combinado será transcrito e resumido novamente para produzir uma transcrição e um resumo contínuos.","merging": "Mesclando…","confirm": "Mesclar",- "videoNote": "Estas gravações incluem vídeo. A mesclagem combina apenas o áudio; a gravação mesclada não terá vídeo."+ "videoNote": "Estas gravações incluem vídeo. A mesclagem combina apenas o áudio; a gravação mesclada não terá vídeo.",+ "audioPreparing": "O áudio ainda está sendo preparado. Poderá ser reproduzido em instantes."}}\ No newline at end of filediff --git a/static/locales/ru.json b/static/locales/ru.jsonindex 98e24ed2..197b4ab9 100644--- a/static/locales/ru.json+++ b/static/locales/ru.json@@ -1875,6 +1875,7 @@"reprocessNote": "Объединённый звук будет заново расшифрован и обобщён, чтобы создать непрерывную расшифровку и резюме.","merging": "Объединение…","confirm": "Объединить",- "videoNote": "Эти записи содержат видео. При объединении сохраняется только звук; в объединённой записи видео не будет."+ "videoNote": "Эти записи содержат видео. При объединении сохраняется только звук; в объединённой записи видео не будет.",+ "audioPreparing": "Аудио ещё готовится. Оно будет доступно для воспроизведения через мгновение."}}\ No newline at end of filediff --git a/static/locales/zh.json b/static/locales/zh.jsonindex 45245f58..66b1b02f 100644--- a/static/locales/zh.json+++ b/static/locales/zh.json@@ -1875,6 +1875,7 @@"reprocessNote": "合并后的音频将被重新转录和总结,以生成连续的转录文本和摘要。","merging": "正在合并…","confirm": "合并",- "videoNote": "这些录音包含视频。合并仅会合并音频;合并后的录音将不包含视频。"+ "videoNote": "这些录音包含视频。合并仅会合并音频;合并后的录音将不包含视频。",+ "audioPreparing": "音频仍在准备中,稍后即可播放。"}}\ No newline at end of filediff --git a/templates/components/detail/audio-player.html b/templates/components/detail/audio-player.htmlindex a3e01fd6..8cd8b1ee 100644--- a/templates/components/detail/audio-player.html+++ b/templates/components/detail/audio-player.html@@ -141,8 +141,9 @@<div class="flex items-center gap-2"><!-- Play/Pause Button --><button @click="toggleAudioPlayback"- class="w-10 h-10 flex items-center justify-center rounded-full player-play-button transition-all duration-200 flex-shrink-0 shadow-md hover:shadow-lg active:scale-95"- :title="audioIsPlaying ? t('tooltips.pause') : t('tooltips.play')">+ :disabled="selectedRecording && selectedRecording.audio_ready === false"+ class="w-10 h-10 flex items-center justify-center rounded-full player-play-button transition-all duration-200 flex-shrink-0 shadow-md hover:shadow-lg active:scale-95 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:shadow-md"+ :title="(selectedRecording && selectedRecording.audio_ready === false) ? t('mergeRecordings.audioPreparing') : (audioIsPlaying ? t('tooltips.pause') : t('tooltips.play'))"><i :class="audioIsPlaying ? 'fas fa-pause' : 'fas fa-play'" class="text-base" :style="!audioIsPlaying ? 'margin-left: 2px' : ''"></i></button>diff --git a/templates/components/detail/desktop-bottom-player.html b/templates/components/detail/desktop-bottom-player.htmlindex 81b8babf..b34fb5c8 100644--- a/templates/components/detail/desktop-bottom-player.html+++ b/templates/components/detail/desktop-bottom-player.html@@ -116,8 +116,9 @@<div v-show="!videoFullscreen" class="flex items-center gap-3 min-w-0"><!-- Play/Pause --><button @click="toggleAudioPlayback"- class="w-10 h-10 flex items-center justify-center rounded-full player-play-button transition-all duration-200 flex-shrink-0 shadow-md hover:shadow-lg hover:scale-105"- :title="audioIsPlaying ? t('tooltips.pause') : t('tooltips.play')">+ :disabled="selectedRecording && selectedRecording.audio_ready === false"+ class="w-10 h-10 flex items-center justify-center rounded-full player-play-button transition-all duration-200 flex-shrink-0 shadow-md hover:shadow-lg hover:scale-105 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:scale-100"+ :title="(selectedRecording && selectedRecording.audio_ready === false) ? t('mergeRecordings.audioPreparing') : (audioIsPlaying ? t('tooltips.pause') : t('tooltips.play'))"><i :class="audioIsPlaying ? 'fas fa-pause' : 'fas fa-play'" class="text-base" :style="!audioIsPlaying ? 'margin-left: 2px' : ''"></i></button>