fix(bug).when generating text that contains only punctuation marks or whitespace characters, the CPU usage reaches 100%, and the process crashes.

This commit is contained in:
0xCAFEBABE0
2024-12-12 16:49:39 +08:00
parent 07352a50b3
commit 84015697c2
2 changed files with 11 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ from torch.nn import functional as F
from contextlib import nullcontext
import uuid
from cosyvoice.utils.common import fade_in_out
from cosyvoice.utils.common import is_only_punctuation
class CosyVoiceModel:
@@ -145,6 +146,9 @@ class CosyVoiceModel:
llm_prompt_speech_token=torch.zeros(1, 0, dtype=torch.int32),
flow_prompt_speech_token=torch.zeros(1, 0, dtype=torch.int32),
prompt_speech_feat=torch.zeros(1, 0, 80), stream=False, speed=1.0, **kwargs):
if is_only_punctuation(text):
logging.info('only punctuation, skip synthesis{}'.format(text))
return {'tts_speech': torch.zeros(1, int(0.01 * 22050))} #返回10ms空白音频保证了一致的上下游处理逻辑
# this_uuid is used to track variables related to this inference thread
this_uuid = str(uuid.uuid1())
with self.lock: