OpenAITTSSession
Base classes¶
| Name | Children | Inherits |
|---|---|---|
| TTSSession anyvoice.base Abstract base class for TTS synthesis sessions. |
⋔ Inheritance diagram¶
graph TD
2431629156["openai.OpenAITTSSession"]
2396137972["base.TTSSession"]
925645236["abc.ABC"]
2751680898["builtins.object"]
2396137972 --> 2431629156
925645236 --> 2396137972
2751680898 --> 925645236
🛈 DocStrings¶
Bases: TTSSession
TTS session using OpenAI's streaming API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AsyncOpenAI | None
|
OpenAI async client (owned by the caller, not closed by the session). |
None
|
model
|
TTSModel
|
TTS model to use. |
'tts-1'
|
voice
|
TTSVoice
|
Voice for synthesis. |
'alloy'
|
speed
|
float
|
Speech speed (0.25 to 4.0). |
1.0
|
chunk_size
|
int
|
Size of audio chunks to yield. |
1024
|
client_factory
|
Callable[[], AsyncOpenAI] | None
|
Creates a client when none is given; the session owns that client and closes it on exit (a later use creates a new one). |
None
|
Source code in src/anyvoice/providers/openai.py
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Close the client if the session created it.
Source code in src/anyvoice/providers/openai.py
synthesize
async
¶
Synthesize text to PCM audio using OpenAI's streaming API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to synthesize. |
required |
Yields:
| Type | Description |
|---|---|
AsyncIterator[bytes]
|
PCM audio chunks (16-bit signed, mono, 24kHz). |