When using the livekit-plugins-openai TTS class configured with a custom base_url to route requests to DeepInfra’s OpenAI-compatible endpoint, the API successfully processes the request and logs show usage/successful responses, but no audio output is produced or played back on the client side.
from livekit.plugins import assemblyai, google, silero
from livekit.plugins.openai import TTS
async def create_interview_session(
tts: TTS, llm: google.LLM, stt: assemblyai.STT
) -> AgentSession:
"""Factory that creates the configured AgentSession"""
return AgentSession(
stt=stt,
llm=llm,
tts=tts,
vad=silero.VAD.load(activation_threshold=0.7),
turn_detection="stt",
min_endpointing_delay=0,
)
tts = TTS(
base_url="https://api.deepinfra.com/v1",
api_key=settings.TTS_API_KEY,
model="hexgrad/Kokoro-82M",
voice="af_bella",
)
Your base_url and key are fine the model name is what’s breaking it. livekit-plugins-openai only takes the raw-audio branch for tts-1/tts-1-hd (AUDIO_STREAM_MODELS (https://github.com/livekit/agents/blob/main/livekit-plugins/livekit-plugins-penai/livekit/plugins/openai/tts.py)); anything else, including hexgrad/Kokoro-82M, goes to SSEChunkedStream, which sends stream_format=“sse” and only emits audio from lines starting with data: carrying a speech.audio.delta. DeepInfra just returns plain MP3 bytes, so no line ever matches, nothing gets pushed, and you get a billed 200 with zero frames and no error.
Force the audio branch and it plays:
from livekit.agents.types import DEFAULT_API_CONNECT_OPTIONS
from livekit.plugins.openai.tts import TTS, AudioChunkedStream
class DeepInfraTTS(TTS):
def synthesize(self, text, *, conn_options=DEFAULT_API_CONNECT_OPTIONS):
return AudioChunkedStream(tts=self, input_text=text, conn_options=conn_options)
First of all huge thanks you for help.
The current method works but its slow than usual.
Do you have any recommendation for cheap and fast alternative?
You can use fishaudio tts? its cheaper and faster i think, it also has s2.1 pro free model currently
Quick update this is fixed upstream. The plugin now picks the parser from the response content-type instead of the model name, so DeepInfra works with no workaround: fix(openai): read TTS response by content-type, not model name by abidullahdev · Pull Request #6930 · livekit/agents · GitHub
Should be in the next release. Until then, AUDIO_STREAM_MODELS.add(“hexgrad/Kokoro-82M”) at import time is the smallest patch if you want to stay on Kokoro.