Skip to content

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

Python

Add pause/resume to in-app recording (#338): MediaRecorder pause freezes the media timeline so meeting breaks are excluded with no silent gap; timer and level meter freeze while paused, with a Pause/Resume toggle in the recording view

Murtaza Nasira213c05e106e
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index 1c1e27be..fc7d26d6 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -360,6 +360,7 @@ document.addEventListener('DOMContentLoaded', async () => {
// --- Audio Recording State ---
const isRecording = ref(false);
+ const isPaused = ref(false);
const mediaRecorder = ref(null);
const audioChunks = ref([]);
const audioBlobURL = ref(null);
@@ -1643,7 +1644,7 @@ document.addEventListener('DOMContentLoaded', async () => {
availableFolders, selectedFolderId, foldersEnabled, filterFolder,
// Audio Recording
- isRecording, mediaRecorder, audioChunks, audioBlobURL, recordingTime, recordingInterval,
+ isRecording, isPaused, mediaRecorder, audioChunks, audioBlobURL, recordingTime, recordingInterval,
canRecordAudio, canRecordSystemAudio, systemAudioSupported, systemAudioError,
recordingNotes, showSystemAudioHelp, showSystemAudioHelpModal, disableAudioProcessing,
recordSystemVideo, recordingVideoActive,
diff --git a/static/js/modules/composables/audio.js b/static/js/modules/composables/audio.js
index e788ec58..138375d9 100644
--- a/static/js/modules/composables/audio.js
+++ b/static/js/modules/composables/audio.js
@@ -9,7 +9,7 @@ import * as ServerSessions from '../db/server-recording-sessions.js';
export function useAudio(state, utils) {
const {
- isRecording, mediaRecorder, audioContext, analyser, micAnalyser, systemAnalyser,
+ isRecording, isPaused, mediaRecorder, audioContext, analyser, micAnalyser, systemAnalyser,
audioChunks, recordingTime, recordingInterval, recordingMode, audioBlobURL,
estimatedFileSize, actualBitrate, recordingNotes, recordingQuality,
maxRecordingMB, fileSizeWarningShown, sizeCheckInterval, isServerStreamedRecording, isFinalizingRecording, recordingDisclaimer,
@@ -391,6 +391,7 @@ export function useAudio(state, utils) {
try {
recordingMode.value = mode;
recordingVideoActive.value = false;
+ if (isPaused) isPaused.value = false;
audioChunks.value = [];
// On resume, continue the on-screen timer and size estimate from
// where the prior segment left off so both reflect the WHOLE
@@ -849,6 +850,10 @@ export function useAudio(state, utils) {
// then gets the warning on its first tick.
let durationWarningShown = false;
recordingInterval.value = setInterval(() => {
+ // Freeze the elapsed-time counter while paused (#338). The
+ // interval keeps running so the max-duration closure survives a
+ // pause/resume; it just skips ticking.
+ if (isPaused && isPaused.value) return;
recordingTime.value++;
if (!durationWarningShown && recordingTime.value >= recordingMaxSeconds * 0.8) {
durationWarningShown = true;
@@ -911,11 +916,63 @@ export function useAudio(state, utils) {
}
};
+ // Stop recording
+ // Pause an in-progress recording. MediaRecorder.pause() freezes the media
+ // timeline, so the audio resumes contiguously with no silent gap — meeting
+ // breaks are simply excluded from the recording (#338). Works on every
+ // capture path (mic/system/both, legacy in-RAM and server-streamed) since
+ // it operates purely at the MediaRecorder level.
+ const pauseRecording = () => {
+ const recorder = mediaRecorder.value;
+ if (!recorder || !isRecording.value || (isPaused && isPaused.value)) return;
+ if (recorder.state !== 'recording') return;
+ try {
+ recorder.pause();
+ } catch (e) {
+ console.warn('[Recording] pause() failed:', e);
+ return;
+ }
+ if (isPaused) isPaused.value = true;
+ // The capture tracks stay live while paused, so freeze the level meter —
+ // otherwise it would keep animating to incoming (unrecorded) audio.
+ if (animationFrameId.value) {
+ cancelAnimationFrame(animationFrameId.value);
+ animationFrameId.value = null;
+ }
+ showToast(
+ (utils.t && utils.t('toasts.recordingPaused')) || 'Recording paused',
+ 'fa-circle-pause',
+ 3000
+ );
+ };
+
+ // Resume a paused recording: MediaRecorder continues the same stream, so the
+ // assembled file stays a single valid container (no new header).
+ const resumeRecording = () => {
+ const recorder = mediaRecorder.value;
+ if (!recorder || !isRecording.value || !(isPaused && isPaused.value)) return;
+ if (recorder.state !== 'paused') return;
+ try {
+ recorder.resume();
+ } catch (e) {
+ console.warn('[Recording] resume() failed:', e);
+ return;
+ }
+ if (isPaused) isPaused.value = false;
+ drawVisualizers(); // restart the level meter
+ showToast(
+ (utils.t && utils.t('toasts.recordingResumed')) || 'Recording resumed',
+ 'fa-circle-play',
+ 3000
+ );
+ };
+
// Stop recording
const stopRecording = async () => {
if (mediaRecorder.value && isRecording.value) {
mediaRecorder.value.stop();
isRecording.value = false;
+ if (isPaused) isPaused.value = false;
_detachVideoPreview();
// Clear the recording timer
@@ -1353,6 +1410,7 @@ export function useAudio(state, utils) {
audioBlobURL.value = null;
audioChunks.value = [];
isRecording.value = false;
+ if (isPaused) isPaused.value = false;
recordingTime.value = 0;
if (recordingInterval.value) clearInterval(recordingInterval.value);
recordingNotes.value = '';
@@ -1451,6 +1509,8 @@ export function useAudio(state, utils) {
// Update file size estimate
const updateFileSizeEstimate = () => {
if (!isRecording.value || !audioChunks.value.length) return;
+ // No new chunks arrive while paused (#338); leave the estimate frozen.
+ if (isPaused && isPaused.value) return;
// Include bytes already uploaded before a resume so the estimate (and
// the derived bitrate) reflect the whole recording, not just the new
@@ -1586,6 +1646,8 @@ export function useAudio(state, utils) {
return {
startRecording,
+ pauseRecording,
+ resumeRecording,
stopRecording,
discardRecording,
normalizeLiveMediaDuration,
diff --git a/static/locales/de.json b/static/locales/de.json
index 9a58ee06..bbd94ec2 100644
--- a/static/locales/de.json
+++ b/static/locales/de.json
@@ -1774,6 +1774,8 @@
"processingCompleted": "Verarbeitung abgeschlossen!",
"processingFailed": "Verarbeitung fehlgeschlagen",
"recordingFinalized": "Aufnahme zur Verarbeitung hochgeladen",
+ "recordingPaused": "Aufnahme pausiert",
+ "recordingResumed": "Aufnahme fortgesetzt",
"recordingMaxDurationApproaching": "Die Aufnahme wird in etwa {{minutes}} Minuten automatisch gestoppt (Höchstdauer).",
"resumedRecordingNotIncognito": "Inkognito wurde deaktiviert: Diese fortgesetzte Aufnahme wurde bereits zum Server übertragen.",
"recordingMaxDurationReached": "Aufnahme hat die Höchstdauer erreicht und wurde automatisch gestoppt.",
diff --git a/static/locales/en.json b/static/locales/en.json
index 3ed209df..c43a10f2 100644
--- a/static/locales/en.json
+++ b/static/locales/en.json
@@ -1774,6 +1774,8 @@
"processingCompleted": "Processing completed!",
"processingFailed": "Processing failed",
"recordingFinalized": "Recording uploaded for processing",
+ "recordingPaused": "Recording paused",
+ "recordingResumed": "Recording resumed",
"recordingMaxDurationApproaching": "Recording will stop automatically in about {{minutes}} minutes (maximum duration).",
"resumedRecordingNotIncognito": "Incognito was turned off: this resumed recording was already streaming to the server.",
"recordingMaxDurationReached": "Recording reached the maximum duration and was stopped automatically.",
diff --git a/static/locales/es.json b/static/locales/es.json
index 3303d2c6..4fdf4712 100644
--- a/static/locales/es.json
+++ b/static/locales/es.json
@@ -1774,6 +1774,8 @@
"processingCompleted": "¡Procesamiento completado!",
"processingFailed": "Error en el procesamiento",
"recordingFinalized": "Grabación subida para procesamiento",
+ "recordingPaused": "Grabación en pausa",
+ "recordingResumed": "Grabación reanudada",
"recordingMaxDurationApproaching": "La grabación se detendrá automáticamente en unos {{minutes}} minutos (duración máxima).",
"resumedRecordingNotIncognito": "El modo incógnito se desactivó: esta grabación reanudada ya se estaba transmitiendo al servidor.",
"recordingMaxDurationReached": "La grabación alcanzó la duración máxima y se detuvo automáticamente.",
diff --git a/static/locales/fr.json b/static/locales/fr.json
index 4d20b83c..6e97bed1 100644
--- a/static/locales/fr.json
+++ b/static/locales/fr.json
@@ -1774,6 +1774,8 @@
"processingCompleted": "Traitement terminé !",
"processingFailed": "Échec du traitement",
"recordingFinalized": "Enregistrement envoyé pour traitement",
+ "recordingPaused": "Enregistrement en pause",
+ "recordingResumed": "Enregistrement repris",
"recordingMaxDurationApproaching": "L'enregistrement s'arrêtera automatiquement dans environ {{minutes}} minutes (durée maximale).",
"resumedRecordingNotIncognito": "Le mode incognito a été désactivé : cet enregistrement repris était déjà transmis au serveur.",
"recordingMaxDurationReached": "L'enregistrement a atteint la durée maximale et s'est arrêté automatiquement.",
diff --git a/static/locales/pt-BR.json b/static/locales/pt-BR.json
index ba4366f7..7e780c5a 100644
--- a/static/locales/pt-BR.json
+++ b/static/locales/pt-BR.json
@@ -1774,6 +1774,8 @@
"processingCompleted": "Processamento concluído!",
"processingFailed": "Falha no processamento",
"recordingFinalized": "Gravação enviada para processamento",
+ "recordingPaused": "Gravação pausada",
+ "recordingResumed": "Gravação retomada",
"recordingMaxDurationApproaching": "A gravação será interrompida automaticamente em cerca de {{minutes}} minutos (duração máxima).",
"resumedRecordingNotIncognito": "O modo anônimo foi desativado: esta gravação retomada já estava sendo transmitida ao servidor.",
"recordingMaxDurationReached": "A gravação atingiu a duração máxima e foi parada automaticamente.",
diff --git a/static/locales/ru.json b/static/locales/ru.json
index 28c215e7..c183a6f7 100644
--- a/static/locales/ru.json
+++ b/static/locales/ru.json
@@ -1774,6 +1774,8 @@
"processingCompleted": "Обработка завершена!",
"processingFailed": "Обработка не удалась",
"recordingFinalized": "Запись отправлена на обработку",
+ "recordingPaused": "Запись приостановлена",
+ "recordingResumed": "Запись возобновлена",
"recordingMaxDurationApproaching": "Запись будет автоматически остановлена примерно через {{minutes}} минут (максимальная длительность).",
"resumedRecordingNotIncognito": "Режим инкогнито отключён: возобновлённая запись уже передавалась на сервер.",
"recordingMaxDurationReached": "Запись достигла максимальной длительности и была остановлена автоматически.",
diff --git a/static/locales/zh.json b/static/locales/zh.json
index 408349e8..fa04f8aa 100644
--- a/static/locales/zh.json
+++ b/static/locales/zh.json
@@ -1774,6 +1774,8 @@
"processingCompleted": "处理完成!",
"processingFailed": "处理失败",
"recordingFinalized": "录音已上传等待处理",
+ "recordingPaused": "录音已暂停",
+ "recordingResumed": "录音已恢复",
"recordingMaxDurationApproaching": "录音将在约 {{minutes}} 分钟后自动停止(已接近最长时长)。",
"resumedRecordingNotIncognito": "隐身模式已关闭:此恢复的录音已在向服务器传输。",
"recordingMaxDurationReached": "录音已达到最长时长,已自动停止。",
diff --git a/templates/components/recording-view.html b/templates/components/recording-view.html
index 188af6f6..a9ecd134 100644
--- a/templates/components/recording-view.html
+++ b/templates/components/recording-view.html
@@ -56,7 +56,7 @@
<div>
<div class="text-xl md:text-2xl font-mono text-[var(--text-accent)]">${formatTime(recordingTime)}</div>
- <p class="text-xs md:text-sm text-[var(--text-muted)]">${ isRecording ? 'Recording in progress...' : 'Recording finished' }</p>
+ <p class="text-xs md:text-sm text-[var(--text-muted)]">${ isRecording ? (isPaused ? 'Paused' : 'Recording in progress...') : 'Recording finished' }</p>
<!-- Real-time file size display -->
<div v-if="isRecording && estimatedFileSize > 0" class="mt-1.5">
<p class="text-xs text-[var(--text-muted)]">
@@ -393,9 +393,20 @@
<!-- BOTTOM: Action Buttons (always pinned) -->
<div class="flex-shrink-0 p-3 md:p-6 bg-[var(--bg-tertiary)] border-t border-[var(--border-primary)]">
- <div v-if="isRecording" class="text-center">
+ <div v-if="isRecording" class="flex gap-3 justify-center">
+ <!-- Pause / Resume toggle (#338): MediaRecorder freezes the media
+ timeline while paused, so meeting breaks are excluded from the
+ recording without a silent gap. -->
+ <button v-if="!isPaused" @click="pauseRecording"
+ class="px-5 md:px-6 py-2.5 md:py-3 bg-[var(--bg-button)] text-[var(--text-button)] rounded-lg hover:bg-[var(--bg-button-hover)] transition-colors text-sm md:text-base flex items-center">
+ <i class="fas fa-pause mr-2"></i>Pause
+ </button>
+ <button v-else @click="resumeRecording"
+ class="px-5 md:px-6 py-2.5 md:py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors text-sm md:text-base flex items-center">
+ <i class="fas fa-play mr-2"></i>Resume
+ </button>
<button @click="stopRecording"
- class="px-6 md:px-8 py-2.5 md:py-3 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors animate-pulse text-sm md:text-base">
+ :class="['px-6 md:px-8 py-2.5 md:py-3 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors text-sm md:text-base flex items-center', isPaused ? '' : 'animate-pulse']">
<i class="fas fa-stop mr-2"></i>Stop Recording
</button>
</div>