base
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| AudioSink anyvoice.base Abstract base class for audio output backends. |
||
| TTSProvider anyvoice.base Abstract base class for TTS providers. |
||
| TTSSession anyvoice.base Abstract base class for TTS synthesis sessions. |
🛈 DocStrings¶
Base classes for TTS providers and audio sinks.
AudioSink
¶
Bases: ABC
Abstract base class for audio output backends.
Audio sinks receive PCM audio chunks and handle output (playback, file writing, etc.).
Usage as context manager
async with SoundDeviceSink() as sink: await sink.write(audio_chunk)
Source code in src/anyvoice/base.py
__aenter__
async
¶
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Exit the sink context, finalize and cleanup.
write
abstractmethod
async
¶
Write a PCM audio chunk to the sink.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk
|
bytes
|
Raw PCM audio data (16-bit signed, mono). |
required |
TTSProvider
¶
Bases: ABC
Abstract base class for TTS providers.
Providers hold credentials and client configuration, and act as factories for lightweight sessions.
Usage
provider = OpenAITTSProvider(api_key="...") session = provider.session(voice="nova", speed=1.0)
Source code in src/anyvoice/base.py
session
abstractmethod
¶
session(**config: Any) -> TTSSession
Create a new synthesis session with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**config
|
Any
|
Provider-specific configuration (voice, speed, etc.). |
{}
|
Returns:
| Type | Description |
|---|---|
TTSSession
|
A new TTSSession configured with the given parameters. |
Source code in src/anyvoice/base.py
TTSSession
¶
Bases: ABC
Abstract base class for TTS synthesis sessions.
A session represents a single synthesis context with specific configuration (voice, speed, etc.). Sessions are lightweight and created by providers.
Usage
session = provider.session(voice="nova") async for chunk in session.synthesize("Hello world"): await sink.write(chunk)
Source code in src/anyvoice/base.py
__aenter__
async
¶
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Exit the session context, cleanup resources.
synthesize
abstractmethod
¶
Synthesize text to PCM audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to synthesize. |
required |
Yields:
| Type | Description |
|---|---|
AsyncIterator[bytes]
|
PCM audio chunks (16-bit signed, mono). |