fix: correct type-check order in _generate() to prevent AttributeError on non-string input

The previous guard `not text.strip() or not isinstance(text, str)` called
.strip() before verifying that text is actually a string, causing an
AttributeError (e.g. for int input) instead of the intended ValueError.

Swap operand order so isinstance check short-circuits first.

Closes #228
This commit is contained in:
cocoon
2026-04-09 16:13:40 +00:00
parent 79c0cf68dd
commit 4f4a5b9f6c
+1 -1
View File
@@ -200,7 +200,7 @@ class VoxCPM:
Yields audio chunks for each generation step if ``streaming=True``, Yields audio chunks for each generation step if ``streaming=True``,
otherwise yields a single array containing the final audio. otherwise yields a single array containing the final audio.
""" """
if not text.strip() or not isinstance(text, str): if not isinstance(text, str) or not text.strip():
raise ValueError("target text must be a non-empty string") raise ValueError("target text must be a non-empty string")
if prompt_wav_path is not None: if prompt_wav_path is not None: