Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Add explicit audio download button for mobile support
Murtaza Nasir6683219fbfa6
diff --git a/src/api/recordings.py b/src/api/recordings.pyindex 2323d451..b834e988 100644--- a/src/api/recordings.py+++ b/src/api/recordings.py@@ -2628,7 +2628,11 @@ def get_status(recording_id):@recordings_bp.route('/audio/<int:recording_id>')@login_requireddef get_audio(recording_id):- """Serve audio file for a recording."""+ """Serve audio file for a recording.++ Query parameters:+ download: If 'true', serves file as attachment for download+ """try:recording = db.session.get(Recording, recording_id)if not recording or not recording.audio_path:@@ -2650,6 +2654,18 @@ def get_audio(recording_id):if not os.path.exists(recording.audio_path):current_app.logger.error(f"Audio file missing from server: {recording.audio_path}")return jsonify({'error': 'Audio file missing from server'}), 404++ # Check if download is requested+ download = request.args.get('download', 'false').lower() == 'true'+ if download:+ # Generate filename from recording title or use default+ filename = recording.title or f'recording_{recording_id}'+ # Sanitize filename and add extension+ filename = "".join(c for c in filename if c.isalnum() or c in (' ', '-', '_')).strip()+ ext = os.path.splitext(recording.audio_path)[1] or '.mp3'+ filename = f"{filename}{ext}"+ return send_file(recording.audio_path, as_attachment=True, download_name=filename)+return send_file(recording.audio_path)except Exception as e:current_app.logger.error(f"Error serving audio for recording {recording_id}: {e}", exc_info=True)diff --git a/static/locales/en.json b/static/locales/en.jsonindex 4f3fd230..aa78c920 100644--- a/static/locales/en.json+++ b/static/locales/en.json@@ -284,6 +284,7 @@"deleteSpeaker": "Delete speaker","deleteTag": "Delete tag","deleteUser": "Delete User",+ "downloadAudio": "Download audio","downloadAsWord": "Download as Word","downloadChat": "Download chat as Word document","downloadNotes": "Download Notes as Word Document",diff --git a/templates/components/detail/audio-player.html b/templates/components/detail/audio-player.htmlindex ca5947c9..f9706319 100644--- a/templates/components/detail/audio-player.html+++ b/templates/components/detail/audio-player.html@@ -8,15 +8,21 @@<span v-text="t('help.audioDeletedMessage')"></span></div><!-- Show audio player if audio is available -->- <audio v-else- ref="audioPlayerElement"- controls- :src="'/audio/' + selectedRecording.id"- :volume="playerVolume"- @volumechange="onPlayerVolumeChange"- @timeupdate="handleAudioTimeUpdate"- class="w-full">- Your browser does not support the audio element.- </audio>+ <div v-else class="flex items-center gap-2">+ <audio ref="audioPlayerElement"+ controls+ :src="'/audio/' + selectedRecording.id"+ :volume="playerVolume"+ @volumechange="onPlayerVolumeChange"+ @timeupdate="handleAudioTimeUpdate"+ class="flex-1">+ Your browser does not support the audio element.+ </audio>+ <a :href="'/audio/' + selectedRecording.id + '?download=true'"+ class="p-2 rounded-lg bg-[var(--bg-tertiary)] hover:bg-[var(--bg-accent-hover)] text-[var(--text-muted)] hover:text-[var(--text-accent)] transition-colors flex-shrink-0"+ :title="t('buttons.downloadAudio') || 'Download audio'">+ <i class="fas fa-download"></i>+ </a>+ </div></div></div>