Repository navigation
Add speech-to-text and text-to-speech endpoints - #428
Merged
Priyanshu-u07 merged 4 commits intoOct 24, 2026
Merged
Conversation
The API key is only validated after the form is read, so uploads are now size-checked first (25 MB). TTS is slow, so input is capped at 4096 characters to stop long texts blocking the speech server. Upstream content types are limited to audio, JSON and text, with nosniff, since /inf shares the dashboard's origin. Signed-off-by: Priyanshu-u07 <connect.priyanshu8271@gmail.com>
Collaborator
|
Reviewed this and pushed a fix commit (fbd39a0) for three issues:
Added 3 tests; they fail without the fix. Full suite shows the same failures as main. Note for the canvas (#429): an LLM answer over 4,096 characters would now get a 400 from TTS, though voice replies are far below that. Follow-ups, not blocking: audio requests don't count toward the token quota yet and behind nginx the default 1 MB body limit will reject real recordings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ModelType.AUDIO_GENERATIONalready lists/v1/audio/speechand/v1/audio/transcriptions, but the inference service didn't serve them, so speech models couldn't be used through InferiaLLM. This adds both, OpenAI-compatible, so a speech-to-text or text-to-speech deployment works with an API key (or the sandbox header) like a chat model.POST /v1/audio/transcriptions: multipartfile+model(other form fields likelanguagepass through). Returns the upstream JSON, e.g.{"text": "..."}.POST /v1/audio/speech: JSON{model, input, voice, ...}. Returns the audio bytes with the upstream content type.model_type = audio_generationand go through the same rate limit, quota, usage log and circuit breaker as the other routes.speaches(speaches, an OpenAI-compatible server for faster-whisper and Kokoro/Piper). Any OpenAI-compatible engine works too, since the paths are on the base adapter.GatewayService.call_upstream_rawfor these two, becausecall_upstreamonly does JSON in/JSON out. It reuses the same URL validation, header sanitizing, concurrency limit, size cap and breaker.model_type. It was already in the gRPCDeploymentmessage but got dropped, so the dashboard couldn't tell an STT model from an LLM.Testing:
src/tests/inference/test_audio_endpoints.py: calls the real routes with anhttpx.MockTransportupstream. It checks the multipart body reaches upstream with the deployment'sinference_model, audio bytes and content type come back, missing fields are a 400, and upstream 4xx is passed through.test_listing_includes_model_typefor the list change.faster-whisper-tiny.en,Kokoro-82M) registered as external deployments, through/inf/v1with an API key: TTS returned a 24 kHz WAV in 2.7s, and sending that WAV to STT came back as the exact sentence. A browser webm/opus recording also transcribes correctly.