Skip to content

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

Python

Persist effective hotwords/initial prompt per recording so they can be surfaced and pre-filled on reprocess (#309)

Murtaza Nasir3339959a107d
diff --git a/src/init_db.py b/src/init_db.py
index 61593431..37b72f5d 100644
--- a/src/init_db.py
+++ b/src/init_db.py
@@ -222,6 +222,13 @@ def initialize_database(app):
if add_column_if_not_exists(engine, 'recording', 'prompt_variables', 'JSON'):
app.logger.info("Added prompt_variables column to recording table")
+ # Effective transcription hints (hotwords / initial prompt) actually used
+ # for a recording, captured at transcription time (issue #309).
+ if add_column_if_not_exists(engine, 'recording', 'resolved_hotwords', 'TEXT'):
+ app.logger.info("Added resolved_hotwords column to recording table")
+ if add_column_if_not_exists(engine, 'recording', 'resolved_initial_prompt', 'TEXT'):
+ app.logger.info("Added resolved_initial_prompt column to recording table")
+
# Add speaker voice profile embedding fields
if add_column_if_not_exists(engine, 'speaker', 'average_embedding', 'BLOB'):
app.logger.info("Added average_embedding column to speaker table")
diff --git a/src/models/recording.py b/src/models/recording.py
index 2ab2b9e2..3fc32a37 100644
--- a/src/models/recording.py
+++ b/src/models/recording.py
@@ -67,6 +67,13 @@ class Recording(db.Model):
# Substituted into {{name}} placeholders in the resolved summary prompt at summarisation time.
prompt_variables = db.Column(db.JSON, nullable=True)
+ # Effective transcription hints actually sent to the ASR for this recording,
+ # captured at transcription time after tag/folder/user and admin-default
+ # resolution. Persisted so the UI can show which hotwords/initial prompt were
+ # used and pre-fill them on reprocess (issue #309). Null = none were applied.
+ resolved_hotwords = db.Column(db.Text, nullable=True)
+ resolved_initial_prompt = db.Column(db.Text, nullable=True)
+
# Folder relationship (one-to-many: a recording belongs to at most one folder)
folder_id = db.Column(db.Integer, db.ForeignKey('folder.id', ondelete='SET NULL'), nullable=True, index=True)
@@ -386,6 +393,8 @@ class Recording(db.Model):
'tags': [tag.to_dict() for tag in visible_tags] if visible_tags else [],
'events': [event.to_dict() for event in self.events] if self.events else [],
'prompt_variables': self.prompt_variables or {},
+ 'resolved_hotwords': self.resolved_hotwords,
+ 'resolved_initial_prompt': self.resolved_initial_prompt,
'duplicate_info': self._dup_from_map_or_query(duplicate_info_map),
'shared_with_count': shared_with_count,
'public_share_count': public_share_count,
diff --git a/src/tasks/processing.py b/src/tasks/processing.py
index 22401513..63663230 100644
--- a/src/tasks/processing.py
+++ b/src/tasks/processing.py
@@ -1641,6 +1641,14 @@ def transcribe_with_connector(app_context, recording_id, filepath, original_file
hotwords = resolved_hotwords
current_app.logger.debug(f"Using admin default hotwords: {hotwords}")
+ # Persist the effective hints actually used for this transcription so
+ # the UI can surface them and pre-fill them on reprocess (issue #309).
+ # At this point hotwords and initial_prompt hold their final values,
+ # after tag/folder/user and admin-default resolution.
+ recording.resolved_hotwords = hotwords or None
+ recording.resolved_initial_prompt = initial_prompt or None
+ db.session.commit()
+
# Check transcription budget before processing
can_proceed, usage_pct, budget_msg = transcription_tracker.check_budget(recording.user_id)
if not can_proceed:
diff --git a/tests/test_cov_processing.py b/tests/test_cov_processing.py
index 391f6a03..f5696082 100644
--- a/tests/test_cov_processing.py
+++ b/tests/test_cov_processing.py
@@ -550,6 +550,84 @@ def test_transcribe_with_connector_audio_success():
mock_summary.assert_called_once()
+def test_transcribe_with_connector_persists_resolved_hints():
+ """Effective hotwords/initial prompt are stored on the recording (#309)."""
+ import time as _time
+ with app.app_context():
+ user = _make_user("trans_hints")
+ rec = _make_recording(user.id, transcription=None, status="PENDING")
+ rid = rec.id
+ connector = _make_connector(text="Body.")
+
+ tmp_path = os.path.join(app.config["UPLOAD_FOLDER"], f"hints_{rid}.mp3")
+ with open(tmp_path, "wb") as f:
+ f.write(b"\x00" * 1024)
+ conv_result = MagicMock()
+ conv_result.was_converted = False
+
+ with patch("src.services.transcription.get_connector", return_value=connector), \
+ patch.object(proc, "is_video_file", return_value=False), \
+ patch.object(proc, "convert_if_needed", return_value=conv_result), \
+ patch.object(proc, "client", MagicMock()), \
+ patch.object(proc, "ENABLE_INQUIRE_MODE", False), \
+ patch.object(proc, "generate_title_task"), \
+ patch.object(proc, "generate_summary_only_task"), \
+ patch.object(proc, "chunking_service") as mock_chunk_svc:
+ mock_chunk_svc.needs_chunking.return_value = False
+ mock_chunk_svc.get_audio_duration.return_value = 120.0
+ proc.transcribe_with_connector(
+ app.app_context(), rid, tmp_path, "cov.mp3", _time.time(),
+ mime_type="audio/mpeg",
+ hotwords="acme, kpi", initial_prompt="This is a board meeting.",
+ )
+
+ db.session.expire_all()
+ out = db.session.get(Recording, rid)
+ assert out.resolved_hotwords == "acme, kpi"
+ assert out.resolved_initial_prompt == "This is a board meeting."
+ # And they surface through serialization for the UI.
+ d = out.to_dict(include_html=False, viewer_user=user)
+ assert d["resolved_hotwords"] == "acme, kpi"
+ assert d["resolved_initial_prompt"] == "This is a board meeting."
+
+
+def test_transcribe_with_connector_resolved_hints_default_none():
+ """With no hints and no admin default, resolved hints persist as NULL (#309)."""
+ import time as _time
+ with app.app_context():
+ user = _make_user("trans_hints_none")
+ rec = _make_recording(user.id, transcription=None, status="PENDING")
+ rid = rec.id
+ connector = _make_connector(text="Body.")
+
+ tmp_path = os.path.join(app.config["UPLOAD_FOLDER"], f"hints_none_{rid}.mp3")
+ with open(tmp_path, "wb") as f:
+ f.write(b"\x00" * 1024)
+ conv_result = MagicMock()
+ conv_result.was_converted = False
+
+ with patch("src.services.transcription.get_connector", return_value=connector), \
+ patch.object(proc, "is_video_file", return_value=False), \
+ patch.object(proc, "convert_if_needed", return_value=conv_result), \
+ patch.object(proc, "client", MagicMock()), \
+ patch.object(proc, "ENABLE_INQUIRE_MODE", False), \
+ patch.object(proc, "generate_title_task"), \
+ patch.object(proc, "generate_summary_only_task"), \
+ patch.object(proc, "chunking_service") as mock_chunk_svc, \
+ patch.object(proc.SystemSetting, "get_setting", return_value=""):
+ mock_chunk_svc.needs_chunking.return_value = False
+ mock_chunk_svc.get_audio_duration.return_value = 120.0
+ proc.transcribe_with_connector(
+ app.app_context(), rid, tmp_path, "cov.mp3", _time.time(),
+ mime_type="audio/mpeg",
+ )
+
+ db.session.expire_all()
+ out = db.session.get(Recording, rid)
+ assert out.resolved_hotwords is None
+ assert out.resolved_initial_prompt is None
+
+
def test_transcribe_with_connector_budget_exceeded_sets_failed():
import time as _time
with app.app_context():