-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speaker identification WIP #46
Open
etown
wants to merge
4
commits into
main
Choose a base branch
from
ethan/speaker-identification
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
alembic/versions/b6aff0a993d7_add_person_and_voicesamples.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Add person and voicesamples | ||
|
||
Revision ID: b6aff0a993d7 | ||
Revises: 33bddba74d25 | ||
Create Date: 2024-03-01 08:56:55.205553 | ||
|
||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlmodel | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'b6aff0a993d7' | ||
down_revision: Union[str, None] = '33bddba74d25' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# Use batch operations to support SQLite ALTER TABLE for adding constraints | ||
with op.batch_alter_table('utterance', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('person_id', sa.Integer(), nullable=True)) | ||
batch_op.create_foreign_key('fk_utterance_person', 'person', ['person_id'], ['id']) | ||
|
||
op.create_table('person', | ||
sa.Column('created_at', sa.DateTime(), nullable=False), | ||
sa.Column('updated_at', sa.DateTime(), nullable=False), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('first_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column('last_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('voicesample', | ||
sa.Column('created_at', sa.DateTime(), nullable=False), | ||
sa.Column('updated_at', sa.DateTime(), nullable=False), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('filepath', sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column('speaker_embeddings', sa.JSON(), nullable=True), | ||
sa.Column('person_id', sa.Integer(), nullable=True), | ||
sa.ForeignKeyConstraint(['person_id'], ['person.id'], name='fk_voicesample_person'), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
|
||
def downgrade() -> None: | ||
# Use batch operations for dropping column with SQLite | ||
with op.batch_alter_table('utterance', schema=None) as batch_op: | ||
batch_op.drop_constraint('fk_utterance_person', type_='foreignkey') | ||
batch_op.drop_column('person_id') | ||
|
||
# Commands for dropping tables remain unchanged | ||
op.drop_table('voicesample') | ||
op.drop_table('person') |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from typing import List, Optional | ||
from sqlmodel import SQLModel, Field, Relationship | ||
from sqlmodel import SQLModel, Field, Relationship, Column, JSON | ||
from datetime import datetime, timezone | ||
from pydantic import BaseModel | ||
from enum import Enum | ||
|
@@ -36,6 +36,8 @@ class Utterance(CreatedAtMixin, table=True): | |
transcription: "Transcription" = Relationship(back_populates="utterances") | ||
|
||
words: List[Word] = Relationship(back_populates="utterance", sa_relationship_kwargs={"cascade": "all, delete-orphan"}) | ||
person_id: Optional[int] = Field(default=None, foreign_key="person.id") | ||
person: Optional["Person"] = Relationship(back_populates="utterances") | ||
|
||
class Transcription(CreatedAtMixin, table=True): | ||
id: Optional[int] = Field(default=None, primary_key=True) | ||
|
@@ -106,6 +108,19 @@ class CaptureSegment(CreatedAtMixin, table=True): | |
|
||
conversation: Optional[Conversation] = Relationship(back_populates="capture_segment_file") | ||
|
||
class Person(CreatedAtMixin, table=True): | ||
id: Optional[int] = Field(default=None, primary_key=True) | ||
first_name: str | ||
last_name: str | ||
voice_samples: List["VoiceSample"] = Relationship(back_populates="person") | ||
utterances: List[Utterance] = Relationship(back_populates="person") | ||
|
||
class VoiceSample(CreatedAtMixin, table=True): | ||
id: Optional[int] = Field(default=None, primary_key=True) | ||
filepath: str = Field(...) | ||
speaker_embeddings: dict = Field(default={}, sa_column=Column(JSON)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the key is embedding model can we name this explicitly speaker_embeddings_by_model? |
||
person_id: Optional[int] = Field(default=None, foreign_key="person.id") | ||
person: Optional["Person"] = Relationship(back_populates="voice_samples") | ||
|
||
# API Response Models | ||
# https://sqlmodel.tiangolo.com/tutorial/fastapi/relationships/#dont-include-all-the-data | ||
|
This file contains 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
Empty file.
8 changes: 8 additions & 0 deletions
8
owl/services/stt/speaker_identification/abstract_speaker_identification_service.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from abc import ABC, abstractmethod | ||
from ....models.schemas import Transcript | ||
|
||
class AbstractSpeakerIdentificationService(ABC): | ||
|
||
@abstractmethod | ||
async def identifiy_speakers(self, transcript: Transcript, persons) -> Transcript: | ||
pass |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to store the vector embedding of the voice here? This way, we would be able to