Make speech streaming default to SSE (#4679)
Signed-off-by: syd520zy <529477025@qq.com>
This commit is contained in:
1 parent
c45ac74d43
commit
11f6a0b72e
39 files changed
+146
-58
No files matched your search
@@ -69,13 +69,15 @@ class OpenAICreateSpeechRequest(BaseModel):
|
||||
default=None,
|
||||
description=(
|
||||
"Streaming output format. 'audio' streams raw pcm/wav bytes; "
|
||||
"'sse' streams OpenAI speech.audio.* SSE events. Omit for non-streaming."
|
||||
"'sse' streams OpenAI speech.audio.* SSE events. If omitted, stream=true "
|
||||
"selects SSE and stream=false remains non-streaming."
|
||||
),
|
||||
)
|
||||
stream: bool = Field(
|
||||
default=False,
|
||||
description=(
|
||||
"Legacy streaming switch; equivalent to stream_format='audio'. "
|
||||
"Streaming switch; defaults to OpenAI speech.audio.* SSE events. "
|
||||
"Set stream_format='audio' to opt into raw pcm/wav byte streaming. "
|
||||
"Requires response_format='pcm' or 'wav'. Speed adjustment is not supported when streaming."
|
||||
),
|
||||
)
|
||||
@@ -292,13 +294,13 @@ class OpenAICreateSpeechRequest(BaseModel):
|
||||
return self
|
||||
|
||||
def is_raw_audio_stream(self) -> bool:
|
||||
return self.stream or self.stream_format == "audio"
|
||||
return self.stream_format == "audio"
|
||||
|
||||
def is_sse_stream(self) -> bool:
|
||||
return self.stream_format == "sse" and not self.is_raw_audio_stream()
|
||||
return (self.stream or self.stream_format == "sse") and not self.is_raw_audio_stream()
|
||||
|
||||
def is_streaming(self) -> bool:
|
||||
return self.is_raw_audio_stream() or self.stream_format == "sse"
|
||||
return self.is_raw_audio_stream() or self.is_sse_stream()
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_streaming_constraints(self) -> "OpenAICreateSpeechRequest":
|
||||
|
||||
@@ -4038,11 +4038,11 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
|
||||
- ref_text: Transcript of reference audio (Base task)
|
||||
- x_vector_only_mode: Use speaker embedding only (Base task)
|
||||
|
||||
Streaming is supported via ``stream_format='audio'`` or the legacy
|
||||
``stream=True`` switch, with ``response_format='pcm'`` or ``'wav'``.
|
||||
``stream_format='sse'`` returns OpenAI ``speech.audio.*`` SSE events instead.
|
||||
Each Code2Wav chunk is yielded as raw audio bytes as soon as it is decoded.
|
||||
For WAV format, a header with placeholder size values is emitted first.
|
||||
Streaming is supported via the ``stream=True`` switch or ``stream_format='sse'``,
|
||||
which return OpenAI ``speech.audio.*`` SSE events. ``stream_format='audio'``
|
||||
opts into raw audio streaming with ``response_format='pcm'`` or ``'wav'``.
|
||||
Raw audio streaming yields each Code2Wav chunk as raw bytes as soon as it is
|
||||
decoded. Raw WAV streaming emits a header with placeholder size values first.
|
||||
"""
|
||||
if self._diffusion_mode:
|
||||
return await self._create_diffusion_speech(request)
|
||||
@@ -4060,14 +4060,14 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
|
||||
)
|
||||
|
||||
try:
|
||||
if request.is_raw_audio_stream():
|
||||
if request.word_timestamps:
|
||||
return self.create_error_response(
|
||||
"word_timestamps=true is currently supported by the WebSocket "
|
||||
"/v1/audio/speech/stream path. Use session.config with "
|
||||
"stream_audio=true and response_format='pcm'."
|
||||
)
|
||||
if request.is_streaming() and request.word_timestamps:
|
||||
return self.create_error_response(
|
||||
"word_timestamps=true is currently supported by the WebSocket "
|
||||
"/v1/audio/speech/stream path. Use session.config with "
|
||||
"stream_audio=true and response_format='pcm'."
|
||||
)
|
||||
|
||||
if request.is_raw_audio_stream():
|
||||
response_format, error = self._validate_speech_streaming_request(
|
||||
request,
|
||||
mode_label="Streaming",
|
||||
|
||||
Reference in new issue
Block a user