[Bugfix] Add seed support to TTS API for deterministic Fish Speech voice generation (#2624)
Signed-off-by: Yiyang Liu <yiyangliu@microsoft.com> Signed-off-by: Yiyang Liu <37043548+ianliuy@users.noreply.github.com> Signed-off-by: Yueqian Lin <70319226+linyueqian@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Yueqian Lin <70319226+linyueqian@users.noreply.github.com>
This commit is contained in:
7 files changed
+94
-9
No files matched your search
@@ -69,6 +69,13 @@ class OpenAICreateSpeechRequest(BaseModel):
|
||||
default=None,
|
||||
description="Maximum tokens to generate",
|
||||
)
|
||||
seed: int | None = Field(
|
||||
default=None,
|
||||
ge=0,
|
||||
le=2**63 - 1,
|
||||
description="Random seed for reproducible generation. When set, ensures "
|
||||
"deterministic output for the same input text and seed value.",
|
||||
)
|
||||
initial_codec_chunk_frames: int | None = Field(
|
||||
default=None,
|
||||
ge=0,
|
||||
|
||||
@@ -1797,6 +1797,22 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
|
||||
sampling_params_list = copy.deepcopy(sampling_params_list)
|
||||
sampling_params_list[0].max_tokens = request.max_new_tokens
|
||||
|
||||
# Propagate per-request seed to sampling params so both Slow AR
|
||||
# and Fast AR produce deterministic output for the same seed.
|
||||
if request.seed is not None and sampling_params_list:
|
||||
if not self._is_fish_speech:
|
||||
logger.warning(
|
||||
"seed=%d requested but deterministic Fast AR seeding is "
|
||||
"only implemented for Fish Speech; other TTS models will "
|
||||
"use the seed for the main AR sampler only.",
|
||||
request.seed,
|
||||
)
|
||||
if sampling_params_list is self.engine_client.default_sampling_params_list:
|
||||
import copy
|
||||
|
||||
sampling_params_list = copy.deepcopy(sampling_params_list)
|
||||
sampling_params_list[0].seed = request.seed
|
||||
|
||||
generator = self.engine_client.generate(
|
||||
prompt=prompt,
|
||||
request_id=request_id,
|
||||
|
||||
Reference in new issue
Block a user