[Frontend] Add configurable output sample rate to Speech API (#6553)
Signed-off-by: 郑倩倩 <2458983186@qq.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
1 parent
a65e89cbd4
commit
49c6fc1540
12 files changed
+453
-14
No files matched your search
@@ -1,7 +1,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
import math
|
||||
from typing import Any, Literal
|
||||
from typing import Annotated, Any, Literal
|
||||
|
||||
import numpy as np
|
||||
from pydantic import AliasChoices, BaseModel, Field, field_validator, model_validator
|
||||
@@ -15,6 +15,7 @@ _MAX_EMBEDDING_DIM = 8192
|
||||
SUPPORTED_AUDIO_FORMATS: frozenset[str] = frozenset({"wav", "pcm", "flac", "mp3", "opus"})
|
||||
SUPPORTED_CHAT_AUDIO_FORMATS: frozenset[str] = SUPPORTED_AUDIO_FORMATS | {"pcm16"}
|
||||
DEFAULT_AUDIO_FORMAT: str = "wav"
|
||||
SpeechSampleRate = Annotated[int, Field(gt=0)]
|
||||
|
||||
|
||||
def _normalize_ref_audio_value(value):
|
||||
@@ -80,6 +81,10 @@ class OpenAICreateSpeechRequest(BaseModel):
|
||||
description="Instructions for voice style/emotion (maps to 'instruct' for Qwen3-TTS)",
|
||||
)
|
||||
response_format: Literal["wav", "pcm", "flac", "mp3", "opus"] = DEFAULT_AUDIO_FORMAT
|
||||
sample_rate: SpeechSampleRate | None = Field(
|
||||
default=None,
|
||||
description="Target sample rate of the returned audio. If omitted, use the model's native sample rate.",
|
||||
)
|
||||
speed: float | None = Field(
|
||||
default=1.0,
|
||||
ge=0.25,
|
||||
@@ -396,6 +401,7 @@ class OpenAICreateAudioGenerateRequest(BaseModel):
|
||||
class CreateAudio(BaseModel):
|
||||
audio_tensor: np.ndarray
|
||||
sample_rate: int = 24000
|
||||
output_sample_rate: int | None = None
|
||||
response_format: str = "wav"
|
||||
speed: float = 1.0
|
||||
base64_encode: bool = True
|
||||
@@ -420,6 +426,7 @@ class SpeechBatchItem(BaseModel):
|
||||
voice: str | None = Field(default=None, validation_alias=AliasChoices("voice", "speaker"))
|
||||
instructions: str | None = None
|
||||
response_format: Literal["wav", "pcm", "flac", "mp3", "opus"] | None = None
|
||||
sample_rate: SpeechSampleRate | 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
|
||||
@@ -440,6 +447,7 @@ class BatchSpeechRequest(BaseModel):
|
||||
voice: str | None = Field(default=None, validation_alias=AliasChoices("voice", "speaker"))
|
||||
instructions: str | None = None
|
||||
response_format: Literal["wav", "pcm", "flac", "mp3", "opus"] = DEFAULT_AUDIO_FORMAT
|
||||
sample_rate: SpeechSampleRate | None = None
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user