[Feat][Qwen3-TTS] Support streaming audio output for websocket (#1719)
Signed-off-by: Sy03 <1370724210@qq.com> Signed-off-by: Yueqian Lin <70319226+linyueqian@users.noreply.github.com> Signed-off-by: linyueqian <linyueqian@outlook.com> Co-authored-by: Yueqian Lin <70319226+linyueqian@users.noreply.github.com> Co-authored-by: linyueqian <linyueqian@outlook.com>
This commit is contained in:
12 files changed
+1719
-265
No files matched your search
@@ -100,3 +100,52 @@ class CreateAudio(BaseModel):
|
||||
class AudioResponse(BaseModel):
|
||||
audio_data: bytes | str
|
||||
media_type: str
|
||||
|
||||
|
||||
class StreamingSpeechSessionConfig(BaseModel):
|
||||
"""Configuration sent as the first WebSocket message for streaming TTS."""
|
||||
|
||||
model: str | None = None
|
||||
voice: str | None = None
|
||||
task_type: Literal["CustomVoice", "VoiceDesign", "Base"] | None = None
|
||||
language: 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)
|
||||
max_new_tokens: int | None = Field(default=None, ge=1)
|
||||
initial_codec_chunk_frames: int | None = Field(
|
||||
default=None,
|
||||
ge=0,
|
||||
description="Initial chunk size for reduced TTFA. Overrides stage config for this session.",
|
||||
)
|
||||
ref_audio: str | None = None
|
||||
ref_text: str | None = None
|
||||
x_vector_only_mode: bool | None = None
|
||||
stream_audio: bool = Field(
|
||||
default=False,
|
||||
description=(
|
||||
"If true, send raw PCM audio chunks progressively over WebSocket. "
|
||||
"Requires response_format='pcm'. Speed adjustment is not supported when streaming."
|
||||
),
|
||||
)
|
||||
split_granularity: Literal["sentence", "clause"] = Field(
|
||||
default="sentence",
|
||||
description=(
|
||||
"Text splitting granularity: 'sentence' splits on .!?。!?, "
|
||||
"'clause' also splits on CJK commas , and semicolons ;."
|
||||
),
|
||||
)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_streaming_constraints(self) -> "StreamingSpeechSessionConfig":
|
||||
if self.stream_audio:
|
||||
if self.response_format != "pcm":
|
||||
raise ValueError(
|
||||
"WebSocket streaming audio (stream_audio=true) requires response_format='pcm'. "
|
||||
f"Got response_format='{self.response_format}'."
|
||||
)
|
||||
if self.speed is None:
|
||||
self.speed = 1.0
|
||||
elif self.speed != 1.0:
|
||||
raise ValueError("Speed adjustment is not supported when stream_audio=true. Set speed=1.0 or omit it.")
|
||||
return self
|
||||
Reference in new issue
Block a user