Skip to content

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

Python

Upload join: skip the pointless conversion of audio parts (the merge re-encodes them), and clearer progress: Processing on server after the bytes are sent, a waiting message for parts of an incomplete join, and Joining for merge jobs, localized in 7 languages

Murtaza Nasire73fe26b8238
diff --git a/src/api/recordings.py b/src/api/recordings.py
index bee47a6f..8ce726eb 100644
--- a/src/api/recordings.py
+++ b/src/api/recordings.py
@@ -2668,8 +2668,16 @@ def ingest_uploaded_recording(
((VIDEO_RETENTION and not keep_audio_only_flag) or VIDEO_PASSTHROUGH_ASR)
and has_video
)
+ # An audio file uploaded to be joined is decoded and re-encoded by the
+ # merge job anyway, so converting it here would only delay the upload
+ # response (minutes for a long recording). Video parts still have their
+ # audio extracted, which is a fast stream copy and keeps a large video
+ # from being stored whole until the join.
+ skip_conversion_for_join = bool(join) and codec_info is not None and not has_video
if keep_video_for_this_upload:
current_app.logger.info(f"Video {'passthrough' if VIDEO_PASSTHROUGH_ASR else 'retention'}: keeping original video, skipping conversion")
+ elif skip_conversion_for_join:
+ current_app.logger.info(f"Join part {original_filename}: skipping conversion, the merge re-encodes it")
else:
# Use shared conversion utility - handles ALL conversion needs (codec conversion + compression)
try:
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index 79c61170..d5002427 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -3267,6 +3267,9 @@ document.addEventListener('DOMContentLoaded', async () => {
}
// Prefer active jobs over completed/failed
+ // A merge job (joining uploaded files, or merging recordings)
+ // runs in the transcription queue but is not transcribing yet.
+ const isJoining = job.job_type === 'merge' && unifiedStatus === 'transcribing';
if (!existing || ['queued', 'transcribing', 'summarizing'].includes(unifiedStatus)) {
items.set(key, {
id: key,
@@ -3275,8 +3278,10 @@ document.addEventListener('DOMContentLoaded', async () => {
clientId: null,
title: job.recording_title || 'Untitled',
status: unifiedStatus,
- progress: unifiedStatus === 'transcribing' ? 50 : (unifiedStatus === 'summarizing' ? 80 : null),
+ statusLabel: isJoining ? t('progressQueue.joining') : null,
+ progress: isJoining ? 25 : (unifiedStatus === 'transcribing' ? 50 : (unifiedStatus === 'summarizing' ? 80 : null)),
progressMessage: unifiedStatus === 'queued' ? `#${job.position || '?'} in queue` :
+ isJoining ? t('progressQueue.joiningMessage') :
unifiedStatus === 'transcribing' ? 'Transcribing audio...' :
unifiedStatus === 'summarizing' ? 'Generating summary...' :
unifiedStatus === 'completed' ? 'Done' : 'Failed',
@@ -3304,7 +3309,7 @@ document.addEventListener('DOMContentLoaded', async () => {
if (upload.status === 'uploading') {
existing.status = 'uploading';
existing.progress = upload.progress || 0;
- existing.progressMessage = 'Uploading...';
+ existing.progressMessage = upload.serverProcessing ? t('progressQueue.processingOnServer') : 'Uploading...';
existing.title = upload.displayName || upload.file?.name || existing.title;
}
continue;
@@ -3318,7 +3323,16 @@ document.addEventListener('DOMContentLoaded', async () => {
if (upload.status === 'uploading') {
unifiedStatus = 'uploading';
- progressMsg = 'Uploading...';
+ // The bytes are sent; the server is checking and
+ // converting the file before it answers.
+ progressMsg = upload.serverProcessing ? t('progressQueue.processingOnServer') : 'Uploading...';
+ } else if (upload.status === 'pending' && upload.joinWaiting) {
+ unifiedStatus = 'queued';
+ progressVal = 100;
+ const waitingFor = upload.joinWaiting.total - upload.joinWaiting.received;
+ progressMsg = waitingFor > 0
+ ? t(waitingFor === 1 ? 'progressQueue.waitingForJoin' : 'progressQueue.waitingForJoinPlural', { count: waitingFor })
+ : t('progressQueue.joiningMessage');
} else if (upload.status === 'pending') {
unifiedStatus = 'queued';
progressVal = 100;
diff --git a/static/js/modules/composables/upload.js b/static/js/modules/composables/upload.js
index 426665b7..dd0736a7 100644
--- a/static/js/modules/composables/upload.js
+++ b/static/js/modules/composables/upload.js
@@ -109,7 +109,7 @@ export function useUpload(state, utils) {
const group = failedItem.join.group;
for (const item of uploadQueue.value) {
if (item === failedItem || !item.join || item.join.group !== group) continue;
- if (['ready', 'uploading', 'completed'].includes(item.status)) {
+ if (['ready', 'uploading', 'pending', 'completed'].includes(item.status)) {
item.joinCancelled = true;
item.status = 'failed';
item.error = message;
@@ -684,12 +684,16 @@ export function useUpload(state, utils) {
const sendUpload = (csrfToken) => new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
+ fileItem.serverProcessing = false;
xhr.upload.onprogress = (e) => {
if (e.lengthComputable) {
// Map upload progress to 5-90% range
fileItem.progress = Math.round(5 + (e.loaded / e.total) * 85);
}
};
+ // Every byte is sent; the server now checks and converts the
+ // file before answering, which can take minutes.
+ xhr.upload.onload = () => { fileItem.serverProcessing = true; };
xhr.onload = () => {
const contentType = xhr.getResponseHeader('content-type') || '';
@@ -756,6 +760,7 @@ export function useUpload(state, utils) {
data = await uploadFileInSlices(fileItem.file, formData, {
onProgress: (fraction) => {
fileItem.progress = Math.round(5 + fraction * 85);
+ fileItem.serverProcessing = fraction >= 1;
},
onXhr: (xhr) => { fileItem._xhr = xhr; },
});
@@ -777,8 +782,11 @@ export function useUpload(state, utils) {
// One part of a join is stored; the part that completes the group
// gets the recording back.
if (data.join_pending) {
- fileItem.status = 'completed';
+ // Stays active until the rest of its join arrives.
+ fileItem.status = 'pending';
fileItem.progress = 100;
+ fileItem.serverProcessing = false;
+ fileItem.joinWaiting = { received: data.received, total: data.total };
return;
}
if (fileItem.join) {
diff --git a/static/locales/de.json b/static/locales/de.json
index 73512428..f1315a73 100644
--- a/static/locales/de.json
+++ b/static/locales/de.json
@@ -1553,7 +1553,13 @@
"uploadingShort": "werden hochgeladen",
"transcribingShort": "werden transkribiert",
"summarizingShort": "werden zusammengefasst",
- "queuedShort": "in der Warteschlange"
+ "queuedShort": "in der Warteschlange",
+ "joiningShort": "zusammengefügt",
+ "joining": "Zusammenfügen",
+ "joiningMessage": "Audiodateien werden zusammengefügt...",
+ "processingOnServer": "Wird auf dem Server verarbeitet...",
+ "waitingForJoin": "Hochgeladen, wartet auf {{count}} weitere Datei zum Zusammenfügen",
+ "waitingForJoinPlural": "Hochgeladen, wartet auf {{count}} weitere Dateien zum Zusammenfügen"
},
"promptVariables": {
"title": "Prompt-Variablen",
diff --git a/static/locales/en.json b/static/locales/en.json
index 1f9c6107..c0fde4b8 100644
--- a/static/locales/en.json
+++ b/static/locales/en.json
@@ -1553,7 +1553,13 @@
"uploadingShort": "uploading",
"transcribingShort": "transcribing",
"summarizingShort": "summarizing",
- "queuedShort": "queued"
+ "queuedShort": "queued",
+ "joiningShort": "joining",
+ "joining": "Joining",
+ "joiningMessage": "Joining audio files...",
+ "processingOnServer": "Processing on server...",
+ "waitingForJoin": "Uploaded, waiting for {{count}} more file to join",
+ "waitingForJoinPlural": "Uploaded, waiting for {{count}} more files to join"
},
"promptVariables": {
"title": "Prompt variables",
diff --git a/static/locales/es.json b/static/locales/es.json
index 55c1dabe..e18f2369 100644
--- a/static/locales/es.json
+++ b/static/locales/es.json
@@ -1553,7 +1553,13 @@
"uploadingShort": "subiendo",
"transcribingShort": "transcribiendo",
"summarizingShort": "resumiendo",
- "queuedShort": "en cola"
+ "queuedShort": "en cola",
+ "joiningShort": "uniendo",
+ "joining": "Uniendo",
+ "joiningMessage": "Uniendo los archivos de audio...",
+ "processingOnServer": "Procesando en el servidor...",
+ "waitingForJoin": "Subido, esperando {{count}} archivo más para unir",
+ "waitingForJoinPlural": "Subido, esperando {{count}} archivos más para unir"
},
"promptVariables": {
"title": "Variables del prompt",
diff --git a/static/locales/fr.json b/static/locales/fr.json
index 21f9d292..31057486 100644
--- a/static/locales/fr.json
+++ b/static/locales/fr.json
@@ -1553,7 +1553,13 @@
"uploadingShort": "en cours d'envoi",
"transcribingShort": "en transcription",
"summarizingShort": "en résumé",
- "queuedShort": "en attente"
+ "queuedShort": "en attente",
+ "joiningShort": "en assemblage",
+ "joining": "Assemblage",
+ "joiningMessage": "Assemblage des fichiers audio...",
+ "processingOnServer": "Traitement sur le serveur...",
+ "waitingForJoin": "Téléversé, en attente de {{count}} autre fichier à assembler",
+ "waitingForJoinPlural": "Téléversé, en attente de {{count}} autres fichiers à assembler"
},
"promptVariables": {
"title": "Variables de l'invite",
diff --git a/static/locales/pt-BR.json b/static/locales/pt-BR.json
index 231468c4..c586e48c 100644
--- a/static/locales/pt-BR.json
+++ b/static/locales/pt-BR.json
@@ -1553,7 +1553,13 @@
"uploadingShort": "enviando",
"transcribingShort": "transcrevendo",
"summarizingShort": "resumindo",
- "queuedShort": "na fila"
+ "queuedShort": "na fila",
+ "joiningShort": "unindo",
+ "joining": "Unindo",
+ "joiningMessage": "Unindo os arquivos de áudio...",
+ "processingOnServer": "Processando no servidor...",
+ "waitingForJoin": "Enviado, aguardando mais {{count}} arquivo para unir",
+ "waitingForJoinPlural": "Enviado, aguardando mais {{count}} arquivos para unir"
},
"promptVariables": {
"hintReprocess": "Estes valores são substituídos nos espaços reservados do prompt resolvido. As edições aqui são salvas na gravação. Valores vazios são substituídos por uma string vazia. Até 8.000 caracteres por valor, 32.000 no total entre todas as variáveis.",
diff --git a/static/locales/ru.json b/static/locales/ru.json
index 856a8788..ee54a389 100644
--- a/static/locales/ru.json
+++ b/static/locales/ru.json
@@ -1553,7 +1553,13 @@
"uploadingShort": "загружается",
"transcribingShort": "расшифровывается",
"summarizingShort": "резюмируется",
- "queuedShort": "в очереди"
+ "queuedShort": "в очереди",
+ "joiningShort": "объединяется",
+ "joining": "Объединение",
+ "joiningMessage": "Объединение аудиофайлов...",
+ "processingOnServer": "Обработка на сервере...",
+ "waitingForJoin": "Загружено, ожидание файлов для объединения: {{count}}",
+ "waitingForJoinPlural": "Загружено, ожидание файлов для объединения: {{count}}"
},
"promptVariables": {
"title": "Переменные подсказки",
diff --git a/static/locales/zh.json b/static/locales/zh.json
index b3d7d12e..ac196c35 100644
--- a/static/locales/zh.json
+++ b/static/locales/zh.json
@@ -1553,7 +1553,13 @@
"uploadingShort": "个正在上传",
"transcribingShort": "个正在转录",
"summarizingShort": "个正在生成摘要",
- "queuedShort": "个排队中"
+ "queuedShort": "个排队中",
+ "joiningShort": "合并中",
+ "joining": "合并中",
+ "joiningMessage": "正在合并音频文件...",
+ "processingOnServer": "正在服务器上处理...",
+ "waitingForJoin": "已上传,等待另外 {{count}} 个文件以便合并",
+ "waitingForJoinPlural": "已上传,等待另外 {{count}} 个文件以便合并"
},
"promptVariables": {
"title": "提示变量",
diff --git a/templates/components/progress-popup.html b/templates/components/progress-popup.html
index 6698ed90..a5933b91 100644
--- a/templates/components/progress-popup.html
+++ b/templates/components/progress-popup.html
@@ -60,8 +60,11 @@
<span v-if="activeProgressItems.filter(i => i.status === 'uploading').length > 0">
${ activeProgressItems.filter(i => i.status === 'uploading').length } ${ t('progressQueue.uploadingShort') }<span v-if="activeProgressItems.filter(i => i.status !== 'uploading').length > 0">, </span>
</span>
- <span v-if="activeProgressItems.filter(i => i.status === 'transcribing').length > 0">
- ${ activeProgressItems.filter(i => i.status === 'transcribing').length } ${ t('progressQueue.transcribingShort') }<span v-if="activeProgressItems.filter(i => ['summarizing', 'queued'].includes(i.status)).length > 0">, </span>
+ <span v-if="activeProgressItems.filter(i => i.statusLabel).length > 0">
+ ${ activeProgressItems.filter(i => i.statusLabel).length } ${ t('progressQueue.joiningShort') }<span v-if="activeProgressItems.filter(i => ['transcribing', 'summarizing', 'queued'].includes(i.status) && !i.statusLabel).length > 0">, </span>
+ </span>
+ <span v-if="activeProgressItems.filter(i => i.status === 'transcribing' && !i.statusLabel).length > 0">
+ ${ activeProgressItems.filter(i => i.status === 'transcribing' && !i.statusLabel).length } ${ t('progressQueue.transcribingShort') }<span v-if="activeProgressItems.filter(i => ['summarizing', 'queued'].includes(i.status)).length > 0">, </span>
</span>
<span v-if="activeProgressItems.filter(i => i.status === 'summarizing').length > 0">
${ activeProgressItems.filter(i => i.status === 'summarizing').length } ${ t('progressQueue.summarizingShort') }<span v-if="activeProgressItems.filter(i => i.status === 'queued').length > 0">, </span>
@@ -103,7 +106,7 @@
item.status === 'transcribing' ? 'bg-purple-500/20 text-purple-500' :
item.status === 'summarizing' ? 'bg-green-500/20 text-green-500' :
'bg-yellow-500/20 text-yellow-500'
- ]">${getStatusDisplay(item.status).label}</span>
+ ]">${item.statusLabel || getStatusDisplay(item.status).label}</span>
</div>
<!-- Progress bar for uploads -->
<div v-if="item.status === 'uploading' && item.progress !== null"
diff --git a/tests/test_upload_join.py b/tests/test_upload_join.py
index 309651bc..c30aef39 100644
--- a/tests/test_upload_join.py
+++ b/tests/test_upload_join.py
@@ -440,3 +440,39 @@ def test_a_lost_response_for_a_sliced_part_is_answered_on_retry(ctx):
finally:
db.session.delete(db.session.get(RecordingSession, session.id))
db.session.commit()
+
+
+# ------------------------------------------------------------ conversion
+
+def test_audio_parts_skip_conversion_but_video_parts_do_not(ctx):
+ """The merge re-encodes every part, so converting an audio part at upload
+ only delays the response; a video part still has its audio extracted."""
+ user = _user()
+ c = _client(user)
+
+ def _convert(filepath, **kwargs):
+ r = MagicMock()
+ r.output_path = filepath
+ r.was_converted = r.was_compressed = False
+ return r
+
+ def _probe(video):
+ return {"has_video": video, "audio_codec": "aac", "video_codec": "h264" if video else None, "duration": 60.0}
+
+ with _upload_mocks(ctx):
+ with patch("src.api.recordings.convert_if_needed", side_effect=_convert) as convert, \
+ patch("src.api.recordings.get_codec_info", return_value=_probe(False)):
+ _part(c, _group(), 0, 2, name="long.m4a")
+ assert convert.call_count == 0
+
+ with patch("src.api.recordings.convert_if_needed", side_effect=_convert) as convert, \
+ patch("src.api.recordings.get_codec_info", return_value=_probe(True)), \
+ patch("src.api.recordings.VIDEO_RETENTION", False):
+ _part(c, _group(), 0, 2, name="talk.mp4")
+ assert convert.call_count == 1
+
+ with patch("src.api.recordings.convert_if_needed", side_effect=_convert) as convert, \
+ patch("src.api.recordings.get_codec_info", return_value=_probe(False)):
+ data = {"file": (io.BytesIO(os.urandom(512)), "single.m4a")}
+ r = c.post("/upload", data=data, content_type="multipart/form-data")
+ assert r.status_code == 202 and convert.call_count == 1