feat(asr): add per-document speaker name persistence#77
Merged
Conversation
Reviewer's GuideAdds persistent per-document speaker name support to ASR transcriptions by introducing a JSON speaker_names column, exposing it via the ASRDocument API, and extending the validation POST endpoint to accept both annotations and speaker_names through a new request schema, with corresponding CRUD updates, migration, and tests. Sequence diagram for POST /asr/validation/document/{id} with ASRValidationRequest and speaker_names persistencesequenceDiagram
actor Client
participant ASRRouter as ASRTranscribeRouter
participant DBSession
participant AudioTranscription as AudioTranscriptionRecord
Client->>ASRRouter: POST /asr/validation/document/{document_id}\nbody ASRValidationRequest
ASRRouter->>DBSession: get_session()
ASRRouter->>DBSession: query AudioTranscription by document_id
DBSession-->>ASRRouter: AudioTranscriptionRecord
ASRRouter->>AudioTranscriptionRecord: set validation from payload.annotations
alt speaker_names is not None
ASRRouter->>AudioTranscriptionRecord: set speaker_names = payload.speaker_names
else speaker_names is None
ASRRouter->>AudioTranscriptionRecord: keep existing speaker_names
end
ASRRouter->>DBSession: add(record)
ASRRouter->>DBSession: commit()
ASRRouter->>DBSession: refresh(record)
ASRRouter-->>Client: 204 No Content
Sequence diagram for GET /asr/validation/document/{id} returning ASRDocument with speaker_namessequenceDiagram
actor Client
participant ASRRouter as ASRTranscribeRouter
participant DBSession
participant AudioTranscription as AudioTranscriptionRecord
participant ASRDocument
Client->>ASRRouter: GET /asr/validation/document/{document_id}
ASRRouter->>DBSession: get_session()
ASRRouter->>DBSession: query AudioTranscription by document_id
DBSession-->>ASRRouter: AudioTranscriptionRecord
ASRRouter->>ASRDocument: construct\n document_id = record.id\n document = record.validation or record.transcription\n speaker_names = record.speaker_names or {}
ASRRouter-->>Client: ASRDocument JSON
ER diagram for updated audio_transcription table with speaker_names JSON columnerDiagram
audio_transcription {
uuid id
string name
json transcription
json validation
json speaker_names
}
Class diagram for ASR validation request and audio transcription models with speaker_namesclassDiagram
class ASRParagraphRequest {
+str text
}
class ASRValidationRequest {
+list~ASRParagraphRequest~ annotations
+dict~str,str~ speaker_names
}
class ASRParagraph {
+str text
+int speaker
+str to_txt()
}
class ASRDocument {
+list~ASRParagraph~ document
+UUID document_id
+dict~str,str~ speaker_names
+str to_txt()
+from_transcription(transcription AudioTranscriptionRead) ASRDocument
}
class AudioTranscriptionBase {
+UUID id
+str name
+list~ASRParagraph~ transcription
+list~ASRParagraph~ validation
+dict~str,str~ speaker_names
}
class AudioTranscription {
}
class AudioTranscriptionUpdate {
+str name
+list~ASRParagraph~ transcription
+list~ASRParagraph~ validation
+dict~str,str~ speaker_names
}
class AudioTranscriptionRead {
}
class AudioTranscriptionCRUD {
+audio_transcription_create_or_update(name str, transcription list~ASRParagraph~, session Session, speaker_names dict~str,str~) AudioTranscription
}
ASRValidationRequest "1" --> "*" ASRParagraphRequest : contains
ASRDocument "1" --> "*" ASRParagraph : contains
AudioTranscriptionBase <|-- AudioTranscription
AudioTranscriptionBase <|-- AudioTranscriptionUpdate
AudioTranscriptionBase <|-- AudioTranscriptionRead
AudioTranscriptionCRUD --> AudioTranscription : creates_updates
ASRDocument --> AudioTranscriptionRead : from_transcription
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
asr_read_document_validationyou manually constructASRDocumentinstead of using the existingASRDocument.from_transcriptionhelper, which could lead to divergence if the response schema evolves; consider delegating to the factory for consistency.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `asr_read_document_validation` you manually construct `ASRDocument` instead of using the existing `ASRDocument.from_transcription` helper, which could lead to divergence if the response schema evolves; consider delegating to the factory for consistency.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Not up to standards ⛔
|
dmazzini
added a commit
that referenced
this pull request
May 27, 2026
879309c8 Feat/entity manager mention feedback (#81) 4d2de106 Fix/responsive home layout (#80) 986e68d2 Fix/homogenize file check ui (#77) 046f8ab9 fix(file-annotator): fix upward autoscroll on search previous navigation (#76) 2ecf75dc feat(dependencies): add dnd-kit packages for drag-and-drop functionality git-subtree-dir: frontend git-subtree-split: 879309c841d8072babc4d06f1686d11cf8cbd03f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
speaker_names: dict[str, str]JSON column to theaudio_transcriptiontable (Alembic migration included; upgrade/downgrade verified)POST /asr/validation/document/{id}body in a newASRValidationRequestschema{annotations, speaker_names}— breaking change from the previous bare-list body (acceptable forrelease/v2.0.0)GET /asr/validation/document/{id}now returnsspeaker_namesin theASRDocumentresponseBehaviour
speaker_namesin POST bodynull){}{"0": "Jueza", ...}Test Plan
test/api/endpoints/routers/asr/)ruff format+ruff checkclean on all changed filesNotes
server_default=sa.text("'{}'")— correct for SQLite. If PostgreSQL support is added later, the cast should be updated to::json.speaker_namesare strings by design (JSON object keys must be strings).Summary by Sourcery
Add per-document speaker name support to ASR validation, including persistence in the database and exposure via the ASR validation API.
New Features:
Enhancements:
Tests:
Chores: