Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
modal based on endpoint
Murtaza Nasir873901244e25
diff --git a/app.py b/app.pyindex aac06f03..f8a8f29d 100644--- a/app.py+++ b/app.py@@ -545,53 +545,6 @@ def update_speakers(recording_id):app.logger.error(f"Error updating speakers for recording {recording_id}: {e}", exc_info=True)return jsonify({'error': str(e)}), 500[email protected]('/recording/<int:recording_id>/reprocess_asr', methods=['POST'])-@login_required-def reprocess_asr(recording_id):- """Reprocess transcription for a given recording using ASR."""- try:- recording = db.session.get(Recording, recording_id)- if not recording:- return jsonify({'error': 'Recording not found'}), 404-- if recording.user_id and recording.user_id != current_user.id:- return jsonify({'error': 'You do not have permission to reprocess this recording'}), 403-- if not recording.audio_path or not os.path.exists(recording.audio_path):- return jsonify({'error': 'Audio file not found for reprocessing'}), 404-- if recording.status in ['PROCESSING', 'SUMMARIZING']:- return jsonify({'error': 'Recording is already being processed'}), 400-- data = request.json- language = data.get('language')- min_speakers = data.get('min_speakers')- max_speakers = data.get('max_speakers')-- recording.transcription = None- recording.summary = None- recording.status = 'PROCESSING'- db.session.commit()-- app.logger.info(f"Starting ASR reprocessing for recording {recording_id}")-- thread = threading.Thread(- target=transcribe_audio_asr,- args=(app.app_context(), recording.id, recording.audio_path, recording.original_filename or f"Recording {recording.id}", language, True, min_speakers, max_speakers)- )- thread.start()-- return jsonify({- 'success': True,- 'message': 'ASR reprocessing started',- 'recording': recording.to_dict()- })-- except Exception as e:- db.session.rollback()- app.logger.error(f"Error reprocessing ASR for recording {recording_id}: {e}")- return jsonify({'error': str(e)}), 500-# --- Chat with Transcription ---@app.route('/chat', methods=['POST'])@login_required@@ -717,15 +670,16 @@ def reprocess_transcription(recording_id):# Decide which transcription method to useif USE_ASR_ENDPOINT:app.logger.info(f"Using ASR endpoint for reprocessing recording {recording_id}")- # For ASR, we can reuse the transcribe_audio_asr function.- # We might need to decide if we want to pass default or new parameters.- # Here, we'll use the user's current settings for diarization.- user_diarize = recording.owner.diarize if recording.owner else ASR_DIARIZE- user_lang = recording.owner.transcription_language if recording.owner else None+ data = request.json or {}+ language = data.get('language') or (recording.owner.transcription_language if recording.owner else None)+ min_speakers = data.get('min_speakers')+ max_speakers = data.get('max_speakers')+ user_diarize = recording.owner.diarize if recording.owner else ASR_DIARIZE+thread = threading.Thread(target=transcribe_audio_asr,- args=(app.app_context(), recording.id, recording.audio_path, recording.original_filename or f"Recording {recording.id}", user_lang, user_diarize, ASR_MIN_SPEAKERS, ASR_MAX_SPEAKERS)+ args=(app.app_context(), recording.id, recording.audio_path, recording.original_filename or f"Recording {recording.id}", language, user_diarize, min_speakers, max_speakers))else:app.logger.info(f"Using standard transcription API for reprocessing recording {recording_id}")diff --git a/static/js/app.js b/static/js/app.jsindex 92d8ee87..21eff3c4 100644--- a/static/js/app.js+++ b/static/js/app.js@@ -38,7 +38,6 @@ document.addEventListener('DOMContentLoaded', () => {const showEditModal = ref(false);const showDeleteModal = ref(false);const showReprocessModal = ref(false);- const showAsrReprocessModal = ref(false);const showSpeakerModal = ref(false);const editingRecording = ref(null); // Holds a *copy* for the modalconst recordingToDelete = ref(null);@@ -954,7 +953,8 @@ document.addEventListener('DOMContentLoaded', () => {// Check for the ASR endpoint flag from the templateconst appDiv = document.getElementById('app');if (appDiv) {- useAsrEndpoint.value = appDiv.classList.contains('use-asr-endpoint');+ const asrFlag = appDiv.dataset.useAsrEndpoint;+ useAsrEndpoint.value = asrFlag === 'True' || asrFlag === 'true';}loadRecordings();initializeDarkMode(); // Initialize dark mode on load@@ -1022,8 +1022,12 @@ document.addEventListener('DOMContentLoaded', () => {cancelReprocess();if (type === 'transcription') {- // ASR logic is now handled by executeAsrReprocess- await performReprocessTranscription(recordingId);+ await performReprocessTranscription(+ recordingId,+ asrReprocessOptions.language,+ asrReprocessOptions.min_speakers,+ asrReprocessOptions.max_speakers+ );} else if (type === 'summary') {await performReprocessSummary(recordingId);}@@ -1031,13 +1035,7 @@ document.addEventListener('DOMContentLoaded', () => {const reprocessTranscription = (recordingId) => {const recording = recordings.value.find(r => r.id === recordingId) || selectedRecording.value;- if (useAsrEndpoint.value) {- // This now calls the specific ASR confirmation modal- confirmAsrReprocess(recording);- } else {- // The original behavior for non-ASR reprocessing- confirmReprocess('transcription', recording);- }+ confirmReprocess('transcription', recording);};const reprocessSummary = (recordingId) => {@@ -1141,16 +1139,23 @@ document.addEventListener('DOMContentLoaded', () => {});};- const performReprocessTranscription = async (recordingId) => {+ const performReprocessTranscription = async (recordingId, language, minSpeakers, maxSpeakers) => {if (!recordingId) {setGlobalError('No recording ID provided for reprocessing.');return;}try {+ const payload = {+ language: language,+ min_speakers: minSpeakers,+ max_speakers: maxSpeakers+ };+const response = await fetch(`/recording/${recordingId}/reprocess_transcription`, {method: 'POST',- headers: { 'Content-Type': 'application/json' }+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify(payload)});const data = await response.json();@@ -1277,44 +1282,6 @@ document.addEventListener('DOMContentLoaded', () => {}};- const performAsrReprocess = async (recordingId, language, minSpeakers, maxSpeakers) => {- if (!recordingId) {- setGlobalError('No recording ID provided for ASR reprocessing.');- return;- }-- try {- const response = await fetch(`/recording/${recordingId}/reprocess_asr`, {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({- language: language,- min_speakers: minSpeakers,- max_speakers: maxSpeakers- })- });-- const data = await response.json();- if (!response.ok) throw new Error(data.error || 'Failed to start ASR reprocessing');-- const index = recordings.value.findIndex(r => r.id === recordingId);- if (index !== -1) {- recordings.value[index] = data.recording;- }-- if (selectedRecording.value?.id === recordingId) {- selectedRecording.value = data.recording;- }-- showToast('ASR reprocessing started', 'fa-sync-alt');- startReprocessingPoll(recordingId);-- } catch (error) {- console.error('ASR Reprocess Error:', error);- setGlobalError(`Failed to start ASR reprocessing: ${error.message}`);- }- };-// --- Chat functionality ---// Resizable panels stateconst transcriptionFlex = ref(2);@@ -1636,11 +1603,7 @@ document.addEventListener('DOMContentLoaded', () => {cancelReprocess,executeReprocess,// ASR Reprocessing- showAsrReprocessModal,asrReprocessOptions,- confirmAsrReprocess,- cancelAsrReprocess,- executeAsrReprocess,// Speaker IdentificationshowSpeakerModal,speakerMap,diff --git a/templates/index.html b/templates/index.htmlindex d25eeaeb..603c9d3d 100644--- a/templates/index.html+++ b/templates/index.html@@ -14,7 +14,11 @@<script src="{{ url_for('static', filename='js/app.js') }}"></script></head><body class="bg-[var(--bg-primary)] text-[var(--text-primary)]">- <div id="app" class="container mx-auto px-4 sm:px-6 lg:px-8 py-6 flex flex-col" :class="{ 'use-asr-endpoint': useAsrEndpoint }">+ <div+ id="app"+ class="container mx-auto px-4 sm:px-6 lg:px-8 py-6 flex flex-col"+ :class="{ 'use-asr-endpoint': useAsrEndpoint }"+ data-use-asr-endpoint="{{ use_asr_endpoint }}"><header class="flex justify-between items-center mb-6 pb-4 border-b border-[var(--border-primary)]"><h1 class="text-3xl font-bold text-[var(--text-primary)] cursor-pointer flex items-center" @click="switchToGalleryView" title="Go to Gallery"><img src="{{ url_for('static', filename='img/favicon.svg') }}" alt="Speakr Logo" class="h-9 w-9 mr-2">