Huge refactoring
This commit is contained in:
47
asr_filter.py
Normal file
47
asr_filter.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from dataclasses import dataclass
|
||||
from asr import AsrRawResult
|
||||
from pydantic import BaseModel
|
||||
|
||||
class AsrFilterSegment(BaseModel):
|
||||
"""Recognized audio segment after cleanup."""
|
||||
|
||||
id: int
|
||||
"""Segment ID, unique within AsrResult"""
|
||||
|
||||
start: float
|
||||
"""Segment start time"""
|
||||
|
||||
end: float
|
||||
"""Segment end time"""
|
||||
|
||||
text: str
|
||||
"""Segment text after cleanup"""
|
||||
|
||||
class AsrFilterResult(BaseModel):
|
||||
"""Result of AsrFilter"""
|
||||
|
||||
segments: list[AsrFilterSegment]
|
||||
"""List of produced segments"""
|
||||
|
||||
class AsrFilter:
|
||||
"""This class performs filtering of raw ASR segments and produces events."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def filter(self, asr_raw_result: AsrRawResult) -> AsrFilterResult:
|
||||
"""Filters raw ASR segments."""
|
||||
result = AsrFilterResult(
|
||||
segments=[]
|
||||
)
|
||||
i = 0
|
||||
for orig in asr_raw_result.segments:
|
||||
s = AsrFilterSegment(
|
||||
id=i,
|
||||
start=orig.start,
|
||||
end=orig.end,
|
||||
text=orig.text.strip()
|
||||
)
|
||||
i += 1
|
||||
result.segments.append(s)
|
||||
return result
|
||||
Reference in New Issue
Block a user