[Feature][Voxtral TTS] Support per-model extra sampling params & add cfg_alpha for Voxtral TTS (#2338)
Signed-off-by: Chen-Yo Sun <chenyo.sun@mistral.ai> Signed-off-by: Yueqian Lin <linyueqian@outlook.com> Co-authored-by: Yueqian Lin <linyueqian@outlook.com>
This commit is contained in:
1 parent
2903f528d2
commit
8e1bbc9ab5
13 files changed
+160
-37
No files matched your search
@@ -298,6 +298,12 @@ def parse_args() -> Namespace:
|
||||
default=None,
|
||||
help="Voice to use instead of audio file.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--cfg-alpha",
|
||||
type=float,
|
||||
default=None,
|
||||
help="CFG alpha for flow-matching guidance (default: use value from stage config, typically 1.2).",
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -349,8 +355,13 @@ def main(args: Any) -> None:
|
||||
|
||||
inputs = compose_request(model_name, text_chunk, audio_prompt_file, args)
|
||||
|
||||
extra_args = {}
|
||||
if args.cfg_alpha is not None:
|
||||
extra_args["cfg_alpha"] = args.cfg_alpha
|
||||
|
||||
sampling_params = SamplingParams(
|
||||
max_tokens=max_num_tokens,
|
||||
extra_args=extra_args if extra_args else None,
|
||||
)
|
||||
sampling_params_list = [
|
||||
sampling_params,
|
||||
|
||||
@@ -216,6 +216,7 @@ def make_update_voice_dropdown(language_voices: dict[str, list[str]]):
|
||||
def run_inference(
|
||||
voice_name: str,
|
||||
text_prompt: str,
|
||||
cfg_alpha: float,
|
||||
base_url: str,
|
||||
model: str,
|
||||
) -> tuple[int, np.ndarray]:
|
||||
@@ -233,6 +234,7 @@ def run_inference(
|
||||
"model": model,
|
||||
"response_format": "wav",
|
||||
"voice": voice_name,
|
||||
"extra_params": {"cfg_alpha": cfg_alpha},
|
||||
}
|
||||
|
||||
response = httpx.post(
|
||||
@@ -377,6 +379,14 @@ def main(
|
||||
placeholder="Enter the text you want to synthesize...",
|
||||
lines=4,
|
||||
)
|
||||
cfg_alpha_slider = gr.Slider(
|
||||
minimum=1.0,
|
||||
maximum=2.0,
|
||||
step=0.1,
|
||||
value=1.2,
|
||||
label="CFG Alpha",
|
||||
info="Flow-matching guidance strength (default: 1.2)",
|
||||
)
|
||||
with gr.Row():
|
||||
reset_btn = gr.Button("Clear")
|
||||
submit_btn = gr.Button("Generate audio", interactive=False)
|
||||
@@ -415,9 +425,9 @@ def main(
|
||||
)
|
||||
|
||||
# --- Wiring inference + persistence to the button ---
|
||||
def _on_submit(voice: str, text: str):
|
||||
def _on_submit(voice: str, text: str, cfg_alpha: float):
|
||||
assert text.strip() != ""
|
||||
sr, audio_array = run_inference(voice, text, base_url, model)
|
||||
sr, audio_array = run_inference(voice, text, cfg_alpha, base_url, model)
|
||||
if outputs_dir is not None:
|
||||
share_id, saved_audio_path = _save_example(
|
||||
outputs_dir,
|
||||
@@ -432,7 +442,7 @@ def main(
|
||||
|
||||
submit_btn.click(
|
||||
fn=_on_submit,
|
||||
inputs=[voice_name, text_prompt],
|
||||
inputs=[voice_name, text_prompt, cfg_alpha_slider],
|
||||
outputs=[output_audio, share_link_box],
|
||||
)
|
||||
|
||||
@@ -446,6 +456,7 @@ def main(
|
||||
language, # language_dropdown
|
||||
voice, # voice_name
|
||||
"", # text_prompt
|
||||
1.2, # cfg_alpha_slider
|
||||
None, # output_audio
|
||||
gr.update(interactive=False), # submit_btn
|
||||
"", # share_link_box
|
||||
@@ -456,7 +467,15 @@ def main(
|
||||
reset_btn.click(
|
||||
fn=make_on_reset(languages, language_voices),
|
||||
inputs=[],
|
||||
outputs=[language_dropdown, voice_name, text_prompt, output_audio, submit_btn, share_link_box],
|
||||
outputs=[
|
||||
language_dropdown,
|
||||
voice_name,
|
||||
text_prompt,
|
||||
cfg_alpha_slider,
|
||||
output_audio,
|
||||
submit_btn,
|
||||
share_link_box,
|
||||
],
|
||||
)
|
||||
|
||||
def make_load_from_share(outputs_dir: Path | None, languages: list[str], language_voices: dict[str, list[str]]):
|
||||
|
||||
Reference in new issue
Block a user