feat: enhance control text processing in VoxCPMDemo

Added regex to strip parentheses from control instructions in the text synthesis method to ensure compatibility with the expected prompt format. This change improves the robustness of the input handling.
This commit is contained in:
gluttony-10
2026-04-21 07:07:24 +00:00
parent 13605c5a0e
commit d3cc88722c
+4
View File
@@ -1,4 +1,5 @@
import os import os
import re
import sys import sys
import logging import logging
import numpy as np import numpy as np
@@ -290,6 +291,9 @@ class VoxCPMDemo:
raise ValueError("Please input text to synthesize.") raise ValueError("Please input text to synthesize.")
control = (control_instruction or "").strip() control = (control_instruction or "").strip()
# Strip any parentheses (half-width/full-width) from control text to avoid
# breaking the "(control)text" prompt format expected by the model.
control = re.sub(r"[()()]", "", control).strip()
final_text = f"({control}){text}" if control else text final_text = f"({control}){text}" if control else text
audio_path = reference_wav_path_input if reference_wav_path_input else None audio_path = reference_wav_path_input if reference_wav_path_input else None