[Feature] Speech batch entrypoint (#1701)

Signed-off-by: dsinghvi <divyanshsinghvi@gmail.com>
Signed-off-by: Divyansh Singhvi <divyanshsinghvi@gmail.com>
This commit is contained in:
dsinghvi authored and GitHub committed 2026-03-24 10:52:01 -04:00
1 parent 7f112041da
commit e7e05a55cf
8 files changed
+1094 -8

No files matched your search

+57 -1
View File
@@ -73,7 +73,7 @@ class OpenAICreateSpeechRequest(BaseModel):
if self.stream:
if self.response_format not in ("pcm", "wav"):
raise ValueError(
"Streaming (stream=true) requires response_format not in ('pcm', 'wav'). "
"Streaming (stream=true) requires response_format='pcm' or 'wav'. "
f"Got response_format='{self.response_format}'."
)
if self.speed is None:
@@ -102,6 +102,62 @@ class AudioResponse(BaseModel):
media_type: str
# --- Batch Speech Models ---
class SpeechBatchItem(BaseModel):
"""Per-item input for batch speech. Only `input` is required;
all other fields override the batch-level defaults when set."""
input: str
voice: str | None = None
instructions: str | None = None
response_format: Literal["wav", "pcm", "flac", "mp3", "aac", "opus"] | None = None
speed: float | None = Field(default=None, ge=0.25, le=4.0)
task_type: Literal["CustomVoice", "VoiceDesign", "Base"] | None = None
language: str | None = None
ref_audio: str | None = None
ref_text: str | None = None
x_vector_only_mode: bool | None = None
max_new_tokens: int | None = None
initial_codec_chunk_frames: int | None = Field(default=None, ge=0)
class BatchSpeechRequest(BaseModel):
"""Top-level request for batch speech generation.
Fields here act as shared defaults; per-item overrides win."""
model: str | None = None
items: list[SpeechBatchItem] = Field(..., min_length=1)
voice: str | None = None
instructions: str | None = None
response_format: Literal["wav", "pcm", "flac", "mp3", "aac", "opus"] = "wav"
speed: float | None = Field(default=1.0, ge=0.25, le=4.0)
task_type: Literal["CustomVoice", "VoiceDesign", "Base"] | None = None
language: str | None = None
ref_audio: str | None = None
ref_text: str | None = None
x_vector_only_mode: bool | None = None
max_new_tokens: int | None = None
initial_codec_chunk_frames: int | None = Field(default=None, ge=0)
class SpeechBatchItemResult(BaseModel):
index: int
status: Literal["success", "error"]
audio_data: str | None = None
media_type: str | None = None
error: str | None = None
class BatchSpeechResponse(BaseModel):
id: str
results: list[SpeechBatchItemResult]
total: int
succeeded: int
failed: int
class StreamingSpeechSessionConfig(BaseModel):
"""Configuration sent as the first WebSocket message for streaming TTS."""