RVC-Boss/GPT-SoVITS · error · ValueError

请输入有效文本

Error message

请输入有效文本

What it means

ValueError raised by TextPreprocessor.filter_text() when every entry in the input list of texts is empty-ish (None, "", " ", "\n"). Text segmentation/splitting eventually calls filter_text before any model runs; with no non-blank segments left there is literally nothing to synthesize, so it fails fast rather than running the models on empty input.

Source

Thrown at GPT_SoVITS/TTS_infer_pack/TextPreprocessor.py:227

        phones = cleaned_text_to_sequence(phones, version)
        return phones, word2ph, norm_text

    def get_bert_inf(self, phones: list, word2ph: list, norm_text: str, language: str):
        language = language.replace("all_", "")
        if language == "zh":
            feature = self.get_bert_feature(norm_text, word2ph).to(self.device)
        else:
            feature = torch.zeros(
                (1024, len(phones)),
                dtype=torch.float32,
            ).to(self.device)

        return feature

    def filter_text(self, texts):
        _text = []
        if all(text in [None, " ", "\n", ""] for text in texts):
            raise ValueError(i18n("请输入有效文本"))
        for text in texts:
            if text in [None, " ", ""]:
                pass
            else:
                _text.append(text)
        return _text

    def replace_consecutive_punctuation(self, text):
        punctuations = "".join(re.escape(p) for p in punctuation)
        pattern = f"([{punctuations}])([{punctuations}])+"
        result = re.sub(pattern, r"\1", text)
        return result

View on GitHub (pinned to d523079fc0)

Solutions

  1. Provide non-empty text to synthesize; check the text field before clicking generate / before calling run().
  2. In calling code, strip and early-return when text is blank: if not (text or '').strip(): return no-op.
  3. For API servers, validate the text payload and return 400 with a clear message instead of surfacing this traceback.

Example fix

# before
audio = handler.run(text="\n \n", text_lang="zh", ...)  # ValueError: 请输入有效文本

# after
text = (raw_text or "").strip()
if not text:
    raise HTTPBadRequest("text is required")
audio = handler.run(text=text, text_lang="zh", ...)
Defensive patterns

Strategy: validation

Validate before calling

if not any((t or "").strip() for t in texts):
    raise ValueError("no non-blank text to synthesize")

Type guard

def has_synthable_text(texts: list[str | None]) -> bool:
    return any(t is not None and t.strip() and t.strip() != "\n" for t in texts)

Prevention

When it happens

Trigger: Calling infer_batch/run (which routes text through TextPreprocessor) with text=None, "", " ", "\n", or text that segments entirely into blank pieces (e.g. a string of only newlines/spaces).

Common situations: Frontend sends an empty textbox value; UI text field was never filled but the generate button clicked; upstream text cleaner stripped everything (e.g. a message made only of emojis/whitespace filtered by sanitize); batch pipeline passes an empty row from a spreadsheet.

Related errors


AI-assisted analysis of RVC-Boss/GPT-SoVITS@d523079fc0 (2026-08-15). Data as JSON: /api/errors/3898fa8cfb89c6ca. Report an issue: GitHub.