multimodalart HF Staff commited on
Commit
91f5562
·
verified ·
1 Parent(s): f7da1c2

Use bundled default audio prompt so conditionals are always prepared

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -19,6 +19,12 @@ subprocess.run(
19
  from chatterbox_flash import ChatterboxFlashTTS
20
 
21
  MODEL_ID = "ResembleAI/chatterbox-flash"
 
 
 
 
 
 
22
  _tts = None
23
 
24
 
@@ -59,8 +65,13 @@ def generate_tts(
59
  "backend": "torch",
60
  }
61
 
62
- if audio_prompt_path:
63
- generate_kwargs["audio_prompt_path"] = audio_prompt_path
 
 
 
 
 
64
 
65
  wav = tts.generate(text_input[:300], **generate_kwargs)
66
  return (tts.sr, wav.squeeze(0).cpu().numpy())
@@ -92,7 +103,8 @@ with gr.Blocks() as demo:
92
  ref_wav = gr.Audio(
93
  sources=["upload", "microphone"],
94
  type="filepath",
95
- label="Reference Audio (for voice cloning)",
 
96
  )
97
 
98
  with gr.Accordion("Advanced settings", open=False):
 
19
  from chatterbox_flash import ChatterboxFlashTTS
20
 
21
  MODEL_ID = "ResembleAI/chatterbox-flash"
22
+ # Chatterbox-Flash has no built-in voice: `generate()` raises
23
+ # "Conditioning not prepared" unless conditionals exist. Ship a default
24
+ # reference clip so zero-shot generation works without a user upload.
25
+ DEFAULT_AUDIO_PROMPT = os.path.join(
26
+ os.path.dirname(os.path.abspath(__file__)), "female_shadowheart4.flac"
27
+ )
28
  _tts = None
29
 
30
 
 
65
  "backend": "torch",
66
  }
67
 
68
+ # Fall back to the bundled reference clip when the user supplies none, so
69
+ # conditionals are always prepared before generation.
70
+ prompt_path = audio_prompt_path or DEFAULT_AUDIO_PROMPT
71
+ generate_kwargs["audio_prompt_path"] = prompt_path
72
+
73
+ if tts.conds is None:
74
+ tts.prepare_conditionals(prompt_path, exaggeration=exaggeration)
75
 
76
  wav = tts.generate(text_input[:300], **generate_kwargs)
77
  return (tts.sr, wav.squeeze(0).cpu().numpy())
 
103
  ref_wav = gr.Audio(
104
  sources=["upload", "microphone"],
105
  type="filepath",
106
+ value=DEFAULT_AUDIO_PROMPT,
107
+ label="Reference Audio (for voice cloning) — defaults to the bundled voice",
108
  )
109
 
110
  with gr.Accordion("Advanced settings", open=False):