Skip to content

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

Python

reprocess based on option

Murtaza Nasira09536938d45
diff --git a/app.py b/app.py
index 905575bb..aac06f03 100644
--- a/app.py
+++ b/app.py
@@ -697,40 +697,51 @@ def reprocess_transcription(recording_id):
recording = db.session.get(Recording, recording_id)
if not recording:
return jsonify({'error': 'Recording not found'}), 404
-
- # Check if the recording belongs to the current user
+
if recording.user_id and recording.user_id != current_user.id:
return jsonify({'error': 'You do not have permission to reprocess this recording'}), 403
-
- # Check if audio file exists
+
if not recording.audio_path or not os.path.exists(recording.audio_path):
return jsonify({'error': 'Audio file not found for reprocessing'}), 404
-
- # Check if already processing
+
if recording.status in ['PROCESSING', 'SUMMARIZING']:
return jsonify({'error': 'Recording is already being processed'}), 400
-
- # Reset transcription and summary, set status to PROCESSING
+
recording.transcription = None
recording.summary = None
recording.status = 'PROCESSING'
db.session.commit()
-
+
app.logger.info(f"Starting transcription reprocessing for recording {recording_id}")
+
+ # Decide which transcription method to use
+ if 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
+
+ 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)
+ )
+ else:
+ app.logger.info(f"Using standard transcription API for reprocessing recording {recording_id}")
+ thread = threading.Thread(
+ target=transcribe_audio_task,
+ args=(app.app_context(), recording.id, recording.audio_path, recording.original_filename or f"Recording {recording.id}")
+ )
- # Start reprocessing in background thread
- thread = threading.Thread(
- target=transcribe_audio_task,
- args=(app.app_context(), recording.id, recording.audio_path, recording.original_filename or f"Recording {recording.id}")
- )
thread.start()
-
+
return jsonify({
- 'success': True,
+ 'success': True,
'message': 'Transcription reprocessing started',
'recording': recording.to_dict()
})
-
+
except Exception as e:
db.session.rollback()
app.logger.error(f"Error reprocessing transcription for recording {recording_id}: {e}")
@@ -1329,7 +1340,8 @@ def admin_get_stats():
# --- Flask Routes ---
@app.route('/')
def index():
- return render_template('index.html')
+ # Pass the ASR config to the template
+ return render_template('index.html', use_asr_endpoint=USE_ASR_ENDPOINT)
@app.route('/recordings', methods=['GET'])
def get_recordings():
diff --git a/static/js/app.js b/static/js/app.js
index 82f17f99..92d8ee87 100644
--- a/static/js/app.js
+++ b/static/js/app.js
@@ -61,6 +61,7 @@ document.addEventListener('DOMContentLoaded', () => {
const isUserMenuOpen = ref(false); // User dropdown menu state
const isMobileMenuOpen = ref(false); // Mobile fly-in menu state
const windowWidth = ref(window.innerWidth); // For reactive screen size
+ const useAsrEndpoint = ref(false);
// --- Audio Recording State ---
const isRecording = ref(false);
@@ -950,9 +951,13 @@ document.addEventListener('DOMContentLoaded', () => {
// --- Lifecycle Hooks ---
onMounted(() => {
+ // Check for the ASR endpoint flag from the template
+ const appDiv = document.getElementById('app');
+ if (appDiv) {
+ useAsrEndpoint.value = appDiv.classList.contains('use-asr-endpoint');
+ }
loadRecordings();
- initializeDarkMode(); // Initialize dark mode on load
-
+ initializeDarkMode(); // Initialize dark mode on load
// Check initial screen size
// This is a bit of a hack as isMobileScreen is computed,
// but we need to react to its initial value for listeners.
@@ -1017,17 +1022,22 @@ document.addEventListener('DOMContentLoaded', () => {
cancelReprocess();
if (type === 'transcription') {
+ // ASR logic is now handled by executeAsrReprocess
await performReprocessTranscription(recordingId);
} else if (type === 'summary') {
await performReprocessSummary(recordingId);
- } else if (type === 'asr') {
- await performAsrReprocess(recordingId);
}
};
const reprocessTranscription = (recordingId) => {
const recording = recordings.value.find(r => r.id === recordingId) || selectedRecording.value;
- confirmReprocess('transcription', recording);
+ if (useAsrEndpoint.value) {
+ // This now calls the specific ASR confirmation modal
+ confirmAsrReprocess(recording);
+ } else {
+ // The original behavior for non-ASR reprocessing
+ confirmReprocess('transcription', recording);
+ }
};
const reprocessSummary = (recordingId) => {
@@ -1037,6 +1047,7 @@ document.addEventListener('DOMContentLoaded', () => {
const confirmAsrReprocess = (recording) => {
reprocessRecording.value = recording;
+ // Reset/pre-fill options when opening the modal
asrReprocessOptions.language = recording.owner?.transcription_language || '';
asrReprocessOptions.min_speakers = null;
asrReprocessOptions.max_speakers = null;
@@ -1045,15 +1056,26 @@ document.addEventListener('DOMContentLoaded', () => {
const cancelAsrReprocess = () => {
showAsrReprocessModal.value = false;
- reprocessRecording.value = null;
+ reprocessRecording.value = null; // Clear the recording being reprocessed
};
const executeAsrReprocess = async () => {
if (!reprocessRecording.value) return;
+
const recordingId = reprocessRecording.value.id;
- await performAsrReprocess(recordingId, asrReprocessOptions.language, asrReprocessOptions.min_speakers, asrReprocessOptions.max_speakers);
- cancelAsrReprocess();
+ // Hide modal before starting
+ showAsrReprocessModal.value = false;
+
+ await performAsrReprocess(
+ recordingId,
+ asrReprocessOptions.language,
+ asrReprocessOptions.min_speakers,
+ asrReprocessOptions.max_speakers
+ );
+
+ // Clear the recording after execution
+ reprocessRecording.value = null;
};
const openSpeakerModal = () => {
@@ -1629,6 +1651,7 @@ document.addEventListener('DOMContentLoaded', () => {
saveSpeakerNames,
highlightedTranscript,
highlightSpeakerInTranscript,
+ useAsrEndpoint,
}
},
delimiters: ['${', '}'] // Keep Vue delimiters distinct from Flask's Jinja
diff --git a/templates/index.html b/templates/index.html
index 4ee2ec5b..d25eeaeb 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -14,7 +14,7 @@
<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">
+ <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 }">
<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">
@@ -112,15 +112,35 @@
</div>
<div>
<p class="text-[var(--text-secondary)] font-medium mb-1">What will happen?</p>
- <p class="text-sm text-[var(--text-muted)]" v-if="reprocessType === 'transcription'">
+ <p class="text-sm text-[var(--text-muted)]" v-if="reprocessType === 'transcription' && !useAsrEndpoint">
The audio will be re-transcribed from scratch. This will also regenerate the title and summary based on the new transcription.
</p>
+ <p class="text-sm text-[var(--text-muted)]" v-else-if="reprocessType === 'transcription' && useAsrEndpoint">
+ The audio will be re-transcribed using the ASR endpoint. This includes diarization and will regenerate the title and summary.
+ </p>
<p class="text-sm text-[var(--text-muted)]" v-else-if="reprocessType === 'summary'">
A new title and summary will be generated based on the existing transcription.
</p>
</div>
</div>
+ <!-- ASR Options -->
+ <div v-if="reprocessType === 'transcription' && useAsrEndpoint" class="space-y-4 pt-4 border-t border-[var(--border-primary)]">
+ <h4 class="text-md font-semibold text-[var(--text-secondary)]">ASR Options</h4>
+ <div>
+ <label for="asr-language-reprocess" class="block text-sm font-medium text-[var(--text-muted)]">Language</label>
+ <input type="text" id="asr-language-reprocess" v-model="asrReprocessOptions.language" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]" placeholder="e.g., en, es, zh (optional)">
+ </div>
+ <div>
+ <label for="asr-min-speakers-reprocess" class="block text-sm font-medium text-[var(--text-muted)]">Min Speakers</label>
+ <input type="number" id="asr-min-speakers-reprocess" v-model.number="asrReprocessOptions.min_speakers" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]" placeholder="Optional">
+ </div>
+ <div>
+ <label for="asr-max-speakers-reprocess" class="block text-sm font-medium text-[var(--text-muted)]">Max Speakers</label>
+ <input type="number" id="asr-max-speakers-reprocess" v-model.number="asrReprocessOptions.max_speakers" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]" placeholder="Optional">
+ </div>
+ </div>
+
<div class="flex items-start space-x-3">
<div class="w-6 h-6 bg-blue-100 rounded-full flex items-center justify-center flex-shrink-0 mt-0.5">
<i class="fas fa-clock text-blue-600 text-xs"></i>
@@ -207,32 +227,6 @@
<button @click="saveSpeakerNames" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">Save Names</button>
</div>
</div>
- </div>
- <!-- ASR Reprocess Modal -->
- <div v-if="showAsrReprocessModal" @click="cancelAsrReprocess" class="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50 p-4 backdrop-blur-sm">
- <div @click.stop class="bg-[var(--bg-secondary)] rounded-xl shadow-2xl w-full max-w-md">
- <div class="p-5 border-b border-[var(--border-primary)]">
- <h3 class="text-xl font-bold text-[var(--text-primary)]">ASR Reprocess Options</h3>
- </div>
- <div class="p-6 space-y-4">
- <div>
- <label for="asr-language" class="block text-sm font-medium text-[var(--text-muted)]">Language</label>
- <input type="text" id="asr-language" v-model="asrReprocessOptions.language" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]" placeholder="e.g., en, es, zh">
- </div>
- <div>
- <label for="asr-min-speakers" class="block text-sm font-medium text-[var(--text-muted)]">Min Speakers</label>
- <input type="number" id="asr-min-speakers" v-model.number="asrReprocessOptions.min_speakers" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]" placeholder="Optional">
- </div>
- <div>
- <label for="asr-max-speakers" class="block text-sm font-medium text-[var(--text-muted)]">Max Speakers</label>
- <input type="number" id="asr-max-speakers" v-model.number="asrReprocessOptions.max_speakers" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]" placeholder="Optional">
- </div>
- </div>
- <div class="bg-[var(--bg-tertiary)] px-6 py-4 flex justify-end space-x-3 border-t border-[var(--border-primary)]">
- <button @click="cancelAsrReprocess" class="px-4 py-2 bg-[var(--bg-secondary)] text-[var(--text-secondary)] rounded-lg border border-[var(--border-secondary)] hover:bg-[var(--bg-tertiary)]">Cancel</button>
- <button @click="executeAsrReprocess" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">Reprocess</button>
- </div>
- </div>
</div>
</div>
{% else %}
@@ -486,17 +480,11 @@
<button @click="copyTranscription($event)" class="text-xs text-[var(--text-muted)] hover:text-[var(--text-accent)] p-1 rounded" title="Copy to clipboard">
<i class="fas fa-copy"></i>
</button>
- <button @click="reprocessTranscription(selectedRecording.id)"
- v-if="selectedRecording && (selectedRecording.status === 'COMPLETED' || selectedRecording.status === 'FAILED')"
- class="text-xs text-[var(--text-muted)] hover:text-[var(--text-accent)] p-1 rounded"
- title="Reprocess transcription">
- <i class="fas fa-sync-alt"></i>
- </button>
- <button @click="confirmAsrReprocess(selectedRecording)"
+ <button @click="reprocessTranscription(selectedRecording.id)"
v-if="selectedRecording && (selectedRecording.status === 'COMPLETED' || selectedRecording.status === 'FAILED')"
class="text-xs text-[var(--text-muted)] hover:text-[var(--text-accent)] p-1 rounded"
- title="Reprocess with ASR">
- <i class="fas fa-cogs"></i>
+ :title="useAsrEndpoint ? 'Reprocess with ASR' : 'Reprocess transcription'">
+ <i :class="useAsrEndpoint ? 'fas fa-cogs' : 'fas fa-sync-alt'"></i>
</button>
</div>
</div>