OpenAITtsSynthesizer (tts/openai.py)

ccgram · src/ccgram/tts/openai.py · python · MIT
voice

OpenAI TTS synthesizer that calls the OpenAI audio/speech API to generate MP3 audio from text.

# Source: https://github.com/alexei-led/ccgram | License: MIT | Copyright 2026 Alexei Ledenev
# Provided via justclaw.it.com; keep this notice with the code.
"""OpenAI TTS synthesis backend.

Uses httpx to call the OpenAI audio/speech endpoint. No openai SDK required.
"""

from __future__ import annotations

import httpx

from .base import TtsAudio, TtsSynthesisError

_OPENAI_BASE_URL = "https://api.openai.com/v1"


class OpenAITtsSynthesizer:
    """Speech synthesizer backed by the OpenAI TTS API."""

    def __init__(
        self,
        api_key: str,
        model: str,
        voice: str,
        base_url: str | None = None,
    ) -> None:
        self._api_key = api_key
        self._model = model
        self._voice = voice
        self._base_url = (base_url or _OPENAI_BASE_URL).rs

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key