Spaces:
Running
on
Zero
Running
on
Zero
fix typos
Browse files
app.py
CHANGED
|
@@ -90,7 +90,7 @@ PREDEFINED_EXAMPLES = {
|
|
| 90 |
"single-speaker-bgm": {
|
| 91 |
"system_prompt": DEFAULT_SYSTEM_PROMPT,
|
| 92 |
"input_text": "<SE_s>[Music]</SE_s> I will remember this, thought Ender, when I am defeated. To keep dignity, and give honor where it's due, so that defeat is not disgrace. And I hope I don't have to do it often. <SE_e>[Music]</SE_e>",
|
| 93 |
-
"description": "Single speaker with BGM using music tag. This is an experimental feature and may need to try multiple times to get the best result.",
|
| 94 |
},
|
| 95 |
}
|
| 96 |
|
|
@@ -127,7 +127,7 @@ def load_voice_presets():
|
|
| 127 |
return {"EMPTY": "No reference voice"}
|
| 128 |
|
| 129 |
|
| 130 |
-
def
|
| 131 |
"""Get the voice path and text for a given voice preset."""
|
| 132 |
voice_path = os.path.join(os.path.dirname(__file__), "voice_examples", f"{voice_preset}.wav")
|
| 133 |
if not os.path.exists(voice_path):
|
|
@@ -225,7 +225,7 @@ def process_text_output(text_output: str):
|
|
| 225 |
|
| 226 |
|
| 227 |
def prepare_chatml_sample(
|
| 228 |
-
|
| 229 |
text: str,
|
| 230 |
reference_audio: Optional[str] = None,
|
| 231 |
reference_text: Optional[str] = None,
|
|
@@ -246,11 +246,11 @@ def prepare_chatml_sample(
|
|
| 246 |
# Custom reference audio
|
| 247 |
audio_base64 = encode_audio_file(reference_audio)
|
| 248 |
ref_text = reference_text or ""
|
| 249 |
-
elif
|
| 250 |
# Voice preset
|
| 251 |
-
voice_path, ref_text =
|
| 252 |
if voice_path is None:
|
| 253 |
-
logger.warning(f"Voice preset {
|
| 254 |
else:
|
| 255 |
audio_base64 = encode_audio_file(voice_path)
|
| 256 |
|
|
@@ -396,7 +396,7 @@ def create_ui():
|
|
| 396 |
label="TTS Template",
|
| 397 |
choices=list(PREDEFINED_EXAMPLES.keys()),
|
| 398 |
value=default_template,
|
| 399 |
-
info="Select a predefined example for system and input messages.
|
| 400 |
)
|
| 401 |
|
| 402 |
# Template description display
|
|
@@ -507,7 +507,7 @@ def create_ui():
|
|
| 507 |
preset_names = [preset for preset in VOICE_PRESETS.keys() if preset != "EMPTY"]
|
| 508 |
if evt.index[0] < len(preset_names):
|
| 509 |
preset = preset_names[evt.index[0]]
|
| 510 |
-
voice_path, _ =
|
| 511 |
if voice_path and os.path.exists(voice_path):
|
| 512 |
return voice_path
|
| 513 |
else:
|
|
|
|
| 90 |
"single-speaker-bgm": {
|
| 91 |
"system_prompt": DEFAULT_SYSTEM_PROMPT,
|
| 92 |
"input_text": "<SE_s>[Music]</SE_s> I will remember this, thought Ender, when I am defeated. To keep dignity, and give honor where it's due, so that defeat is not disgrace. And I hope I don't have to do it often. <SE_e>[Music]</SE_e>",
|
| 93 |
+
"description": "Single speaker with BGM using music tag. This is an experimental feature and you may need to try multiple times to get the best result.",
|
| 94 |
},
|
| 95 |
}
|
| 96 |
|
|
|
|
| 127 |
return {"EMPTY": "No reference voice"}
|
| 128 |
|
| 129 |
|
| 130 |
+
def get_voice_preset(voice_preset):
|
| 131 |
"""Get the voice path and text for a given voice preset."""
|
| 132 |
voice_path = os.path.join(os.path.dirname(__file__), "voice_examples", f"{voice_preset}.wav")
|
| 133 |
if not os.path.exists(voice_path):
|
|
|
|
| 225 |
|
| 226 |
|
| 227 |
def prepare_chatml_sample(
|
| 228 |
+
voice_preset: str,
|
| 229 |
text: str,
|
| 230 |
reference_audio: Optional[str] = None,
|
| 231 |
reference_text: Optional[str] = None,
|
|
|
|
| 246 |
# Custom reference audio
|
| 247 |
audio_base64 = encode_audio_file(reference_audio)
|
| 248 |
ref_text = reference_text or ""
|
| 249 |
+
elif voice_preset != "EMPTY":
|
| 250 |
# Voice preset
|
| 251 |
+
voice_path, ref_text = get_voice_preset(voice_preset)
|
| 252 |
if voice_path is None:
|
| 253 |
+
logger.warning(f"Voice preset {voice_preset} not found, skipping reference audio")
|
| 254 |
else:
|
| 255 |
audio_base64 = encode_audio_file(voice_path)
|
| 256 |
|
|
|
|
| 396 |
label="TTS Template",
|
| 397 |
choices=list(PREDEFINED_EXAMPLES.keys()),
|
| 398 |
value=default_template,
|
| 399 |
+
info="Select a predefined example for system and input messages.",
|
| 400 |
)
|
| 401 |
|
| 402 |
# Template description display
|
|
|
|
| 507 |
preset_names = [preset for preset in VOICE_PRESETS.keys() if preset != "EMPTY"]
|
| 508 |
if evt.index[0] < len(preset_names):
|
| 509 |
preset = preset_names[evt.index[0]]
|
| 510 |
+
voice_path, _ = get_voice_preset(preset)
|
| 511 |
if voice_path and os.path.exists(voice_path):
|
| 512 |
return voice_path
|
| 513 |
else:
|