From 4f4a5b9f6c400216cb66448c6030cb34b26c4f42 Mon Sep 17 00:00:00 2001 From: cocoon <1569339843@qq.com> Date: Thu, 9 Apr 2026 16:13:40 +0000 Subject: [PATCH] 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 --- src/voxcpm/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/voxcpm/core.py b/src/voxcpm/core.py index f5e82b4..2b95928 100644 --- a/src/voxcpm/core.py +++ b/src/voxcpm/core.py @@ -200,7 +200,7 @@ class VoxCPM: Yields audio chunks for each generation step if ``streaming=True``, 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") if prompt_wav_path is not None: