Skip to content

tts

tts

Abstract base classes and data types for text-to-speech backends.

Classes

TTSResult dataclass

TTSResult(audio: bytes, format: str = 'mp3', duration_seconds: float = 0.0, voice_id: str = '', sample_rate: int = 24000, metadata: Dict[str, Any] = dict())

Result of a text-to-speech synthesis.

Functions
save
save(path: Path) -> Path

Write audio bytes to a file and return the path.

Source code in src/openjarvis/speech/tts.py
def save(self, path: Path) -> Path:
    """Write audio bytes to a file and return the path."""
    path.write_bytes(self.audio)
    return path

TTSBackend

Bases: ABC

Abstract base class for text-to-speech backends.

Functions
synthesize abstractmethod
synthesize(text: str, *, voice_id: str = '', speed: float = 1.0, output_format: str = 'mp3') -> TTSResult

Synthesize text to audio.

Source code in src/openjarvis/speech/tts.py
@abstractmethod
def synthesize(
    self,
    text: str,
    *,
    voice_id: str = "",
    speed: float = 1.0,
    output_format: str = "mp3",
) -> TTSResult:
    """Synthesize text to audio."""
available_voices abstractmethod
available_voices() -> List[str]

Return list of available voice IDs.

Source code in src/openjarvis/speech/tts.py
@abstractmethod
def available_voices(self) -> List[str]:
    """Return list of available voice IDs."""
health abstractmethod
health() -> bool

Check if the backend is ready.

Source code in src/openjarvis/speech/tts.py
@abstractmethod
def health(self) -> bool:
    """Check if the backend is ready."""