mirror of
https://github.com/FunAudioLLM/CosyVoice.git
synced 2026-02-05 01:49:25 +08:00
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:
@@ -31,7 +31,7 @@ except ImportError:
|
||||
from tn.chinese.normalizer import Normalizer as ZhNormalizer
|
||||
from tn.english.normalizer import Normalizer as EnNormalizer
|
||||
use_ttsfrd = False
|
||||
from cosyvoice.utils.frontend_utils import contains_chinese, replace_blank, replace_corner_mark, remove_bracket, spell_out_number, split_paragraph
|
||||
from cosyvoice.utils.frontend_utils import contains_chinese, replace_blank, replace_corner_mark, remove_bracket, spell_out_number, split_paragraph, is_only_punctuation
|
||||
|
||||
|
||||
class CosyVoiceFrontEnd:
|
||||
@@ -109,6 +109,10 @@ class CosyVoiceFrontEnd:
|
||||
|
||||
def text_normalize(self, text, split=True):
|
||||
text = text.strip()
|
||||
# When generating text that contains only punctuation marks or whitespace characters
|
||||
# - Returning empty texts ensures consistent processing logic.
|
||||
if is_only_punctuation(text):
|
||||
return []
|
||||
if contains_chinese(text):
|
||||
if self.use_ttsfrd:
|
||||
texts = [i["text"] for i in json.loads(self.frd.do_voicegen_frd(text))["sentences"]]
|
||||
|
||||
Reference in New Issue
Block a user