Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions omnivoice/cli/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@

import argparse
import logging
import random
from typing import Any, Dict

import gradio as gr
import numpy as np
import torch

from omnivoice import OmniVoice, OmniVoiceGenerationConfig
from omnivoice.utils.common import fix_random_seed
from omnivoice.utils.lang_map import LANG_NAMES, lang_display_name


Expand Down Expand Up @@ -176,6 +178,8 @@ def _gen_core(
denoise,
speed,
duration,
seed,
is_random_seed,
preprocess_prompt,
postprocess_output,
mode,
Expand All @@ -184,6 +188,13 @@ def _gen_core(
if not text or not text.strip():
return None, "Please enter the text to synthesize."

if is_random_seed:
seed = random.randint(0, 2 ** 32 - 1)
else:
seed = int(seed or 42)

fix_random_seed(seed)

gen_config = OmniVoiceGenerationConfig(
num_step=int(num_step or 32),
guidance_scale=float(guidance_scale) if guidance_scale is not None else 2.0,
Expand Down Expand Up @@ -220,7 +231,7 @@ def _gen_core(
return None, f"Error: {type(e).__name__}: {e}"

waveform = (audio[0] * 32767).astype(np.int16)
return (sampling_rate, waveform), "Done."
return (sampling_rate, waveform), "Done.", seed

# Allow external wrappers (e.g. spaces.GPU for ZeroGPU Spaces)
_gen = generate_fn if generate_fn is not None else _gen_core
Expand Down Expand Up @@ -290,6 +301,20 @@ def _gen_settings():
label="Guidance Scale (CFG)",
info="Default: 2.0.",
)
sd = gr.Number(
minimum=0,
maximum=4294967295,
precision=0,
value=42,
label="Seed",
info="Default: 42",

)
sd_rnd = gr.Checkbox(
label="Randomize Seed",
value=True,
info="Randomize seed after every generation.",
)
pp = gr.Checkbox(
label="Preprocess Prompt",
value=True,
Expand All @@ -301,7 +326,7 @@ def _gen_settings():
value=True,
info="Remove long silences from generated audio.",
)
return ns, gs, dn, sp, du, pp, po
return ns, gs, dn, sp, du, sd, sd_rnd, pp, po

with gr.Blocks(theme=theme, css=css, title="OmniVoice Demo") as demo:
gr.Markdown(
Expand Down Expand Up @@ -355,6 +380,8 @@ def _gen_settings():
vc_dn,
vc_sp,
vc_du,
vc_sd,
vc_sd_rnd,
vc_pp,
vc_po,
) = _gen_settings()
Expand All @@ -367,7 +394,7 @@ def _gen_settings():
vc_status = gr.Textbox(label="Status / 状态", lines=2)

def _clone_fn(
text, lang, ref_aud, ref_text, instruct, ns, gs, dn, sp, du, pp, po
text, lang, ref_aud, ref_text, instruct, ns, gs, dn, sp, du, sd, sd_rnd, pp, po
):
return _gen(
text,
Expand All @@ -379,6 +406,8 @@ def _clone_fn(
dn,
sp,
du,
sd,
sd_rnd,
pp,
po,
mode="clone",
Expand All @@ -398,10 +427,12 @@ def _clone_fn(
vc_dn,
vc_sp,
vc_du,
vc_sd,
vc_sd_rnd,
vc_pp,
vc_po,
],
outputs=[vc_audio, vc_status],
outputs=[vc_audio, vc_status, vc_sd],
)

# ==============================================================
Expand Down Expand Up @@ -435,6 +466,8 @@ def _clone_fn(
vd_dn,
vd_sp,
vd_du,
vd_sd,
vd_sd_rnd,
vd_pp,
vd_po,
) = _gen_settings()
Expand Down Expand Up @@ -468,7 +501,7 @@ def _build_instruct(groups):
parts.append(v)
return ", ".join(parts)

def _design_fn(text, lang, ns, gs, dn, sp, du, pp, po, *groups):
def _design_fn(text, lang, ns, gs, dn, sp, du, sd, sd_rnd, pp, po, *groups):
return _gen(
text,
lang,
Expand All @@ -479,6 +512,8 @@ def _design_fn(text, lang, ns, gs, dn, sp, du, pp, po, *groups):
dn,
sp,
du,
sd,
sd_rnd,
pp,
po,
mode="design",
Expand All @@ -494,11 +529,13 @@ def _design_fn(text, lang, ns, gs, dn, sp, du, pp, po, *groups):
vd_dn,
vd_sp,
vd_du,
vd_sd,
vd_sd_rnd,
vd_pp,
vd_po,
]
+ vd_groups,
outputs=[vd_audio, vd_status],
outputs=[vd_audio, vd_status, vd_sd],
)

return demo
Expand Down