Skip to content

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

Python

v0.6.4: Fix transcript download for non-diarized transcriptions

Murtaza Nasir93c7e0427f8a
diff --git a/README.md b/README.md
index e5ba5007..5c66d757 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
<a href="https://www.gnu.org/licenses/agpl-3.0"><img alt="AGPL v3" src="https://img.shields.io/badge/License-AGPL_v3-blue.svg"></a>
<a href="https://github.com/murtaza-nasir/speakr/actions/workflows/docker-publish.yml"><img alt="Docker Build" src="https://github.com/murtaza-nasir/speakr/actions/workflows/docker-publish.yml/badge.svg"></a>
<a href="https://hub.docker.com/r/learnedmachine/speakr"><img alt="Docker Pulls" src="https://img.shields.io/docker/pulls/learnedmachine/speakr"></a>
- <a href="https://github.com/murtaza-nasir/speakr/releases/latest"><img alt="Latest Version" src="https://img.shields.io/badge/version-0.6.3-brightgreen.svg"></a>
+ <a href="https://github.com/murtaza-nasir/speakr/releases/latest"><img alt="Latest Version" src="https://img.shields.io/badge/version-0.6.4-brightgreen.svg"></a>
</p>
<p align="center">
diff --git a/VERSION b/VERSION
index e4c57af0..2fc7b367 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-v0.6.3
+v0.6.4
diff --git a/src/api/recordings.py b/src/api/recordings.py
index e066effd..4954ac24 100644
--- a/src/api/recordings.py
+++ b/src/api/recordings.py
@@ -131,44 +131,59 @@ def download_transcript_with_template(recording_id):
millis = int((td.total_seconds() % 1) * 1000)
return f"{hours:02d}:{minutes:02d}:{secs:02d},{millis:03d}"
- # Parse transcription JSON
+ # Parse transcription - handle both JSON (diarized) and plain text formats
+ is_diarized = False
+ transcription_data = None
try:
transcription_data = json.loads(recording.transcription)
- except:
- return jsonify({'error': 'Invalid transcription format'}), 400
-
- # Generate formatted transcript
- output_lines = []
- for index, segment in enumerate(transcription_data, 1):
- line = template_format
-
- # Replace variables
- replacements = {
- '{{index}}': str(index),
- '{{speaker}}': segment.get('speaker', 'Unknown'),
- '{{text}}': segment.get('sentence', ''),
- '{{start_time}}': format_time(segment.get('start_time')),
- '{{end_time}}': format_time(segment.get('end_time')),
- }
+ if isinstance(transcription_data, list):
+ is_diarized = True
+ except (json.JSONDecodeError, TypeError):
+ # Not JSON, treat as plain text
+ pass
+
+ # If plain text transcription, return it as-is (no template formatting applies)
+ if not is_diarized:
+ formatted_transcript = recording.transcription
+ else:
+ # Generate formatted transcript from diarized segments
+ output_lines = []
+ for index, segment in enumerate(transcription_data, 1):
+ line = template_format
+
+ # Replace variables
+ replacements = {
+ '{{index}}': str(index),
+ '{{speaker}}': segment.get('speaker', 'Unknown'),
+ '{{text}}': segment.get('sentence', ''),
+ '{{start_time}}': format_time(segment.get('start_time')),
+ '{{end_time}}': format_time(segment.get('end_time')),
+ }
- for key, value in replacements.items():
- line = line.replace(key, value)
+ for key, value in replacements.items():
+ line = line.replace(key, value)
- # Handle filters
- # Upper case filter
- line = re.sub(r'{{(.*?)\|upper}}', lambda m: replacements.get('{{' + m.group(1) + '}}', '').upper(), line)
- # SRT time filter
- line = re.sub(r'{{start_time\|srt}}', format_srt_time(segment.get('start_time')), line)
- line = re.sub(r'{{end_time\|srt}}', format_srt_time(segment.get('end_time')), line)
+ # Handle filters
+ # Upper case filter
+ line = re.sub(r'{{(.*?)\|upper}}', lambda m: replacements.get('{{' + m.group(1) + '}}', '').upper(), line)
+ # SRT time filter
+ line = re.sub(r'{{start_time\|srt}}', format_srt_time(segment.get('start_time')), line)
+ line = re.sub(r'{{end_time\|srt}}', format_srt_time(segment.get('end_time')), line)
- output_lines.append(line)
+ output_lines.append(line)
- # Join lines
- formatted_transcript = '\n'.join(output_lines)
+ # Join lines
+ formatted_transcript = '\n'.join(output_lines)
# Create response
response = make_response(formatted_transcript)
- filename = f"{recording.title or 'transcript'}_{template.name if template else 'formatted'}.txt"
+ if is_diarized and template:
+ filename = f"{recording.title or 'transcript'}_{template.name}.txt"
+ elif is_diarized:
+ filename = f"{recording.title or 'transcript'}_formatted.txt"
+ else:
+ # Plain text transcription
+ filename = f"{recording.title or 'transcript'}.txt"
filename = re.sub(r'[^a-zA-Z0-9_\-\.]', '_', filename)
response.headers['Content-Type'] = 'text/plain; charset=utf-8'
response.headers['Content-Disposition'] = f'attachment; filename="{filename}"'