mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-31 03:12:16 +00:00
Define the abstract interface for the speech subsystem: SpeechBackend ABC with transcribe/health/supported_formats methods, TranscriptionResult and Segment dataclasses for structured transcription output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
"""Abstract base classes and data types for the speech subsystem."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass, field
|
|
from typing import List, Optional
|
|
|
|
|
|
@dataclass
|
|
class Segment:
|
|
"""A timed segment of transcribed text."""
|
|
|
|
text: str
|
|
start: float # Start time in seconds
|
|
end: float # End time in seconds
|
|
confidence: Optional[float] = None
|
|
|
|
|
|
@dataclass
|
|
class TranscriptionResult:
|
|
"""Result of a speech-to-text transcription."""
|
|
|
|
text: str
|
|
language: Optional[str] = None
|
|
confidence: Optional[float] = None
|
|
duration_seconds: float = 0.0
|
|
segments: List[Segment] = field(default_factory=list)
|
|
|
|
|
|
class SpeechBackend(ABC):
|
|
"""Abstract base class for speech-to-text backends."""
|
|
|
|
backend_id: str = ""
|
|
|
|
@abstractmethod
|
|
def transcribe(
|
|
self,
|
|
audio: bytes,
|
|
*,
|
|
format: str = "wav",
|
|
language: Optional[str] = None,
|
|
) -> TranscriptionResult:
|
|
"""Transcribe audio bytes to text."""
|
|
|
|
@abstractmethod
|
|
def health(self) -> bool:
|
|
"""Check if the backend is ready."""
|
|
|
|
@abstractmethod
|
|
def supported_formats(self) -> List[str]:
|
|
"""Return list of supported audio formats."""
|
|
|
|
|
|
__all__ = ["Segment", "SpeechBackend", "TranscriptionResult"]
|