1
1
from typing import List
2
2
3
- from fast_langdetect import parse_sentence
3
+ from fast_langdetect import detect_multilingual
4
4
from loguru import logger
5
5
6
6
from llmkira .extra .voice import request_cn , request_en
13
13
14
14
def check_string (text ):
15
15
"""
16
- 检查字符串是否符合要求
16
+ 检查字符串是否 TTS 可以处理
17
17
:param text: 字符串
18
18
:return: 是否符合要求
19
19
"""
20
- parsed_text = parse_sentence (text )
20
+ parsed_text = detect_multilingual (text )
21
21
if not parsed_text :
22
22
return False
23
23
lang_kinds = []
24
24
for lang in parsed_text :
25
- if lang .get ("lang" , "RU" ) not in ["ZH" , "EN" ]:
26
- return False
27
- lang_kinds .append (lang .get ("lang" ))
25
+ lang_kinds .append (lang .get ("lang" , "ru" ))
28
26
limit = 200
29
27
if len (set (lang_kinds )) == 1 :
30
- if lang_kinds [0 ] in ["EN " ]:
28
+ if lang_kinds [0 ] in ["en " ]:
31
29
limit = 500
32
30
if "\n \n " in text or text .count ("\n " ) > 3 or len (text ) > limit or "```" in text :
33
31
return False
@@ -59,7 +57,7 @@ async def hook_run(self, *args, **kwargs):
59
57
for message in messages :
60
58
if not check_string (message .text ):
61
59
return args , kwargs
62
- parsed_text = parse_sentence (message .text )
60
+ parsed_text = detect_multilingual (message .text )
63
61
if not parsed_text :
64
62
return args , kwargs
65
63
lang_kinds = []
@@ -68,7 +66,7 @@ async def hook_run(self, *args, **kwargs):
68
66
reecho_api_key = await EnvManager (locate .uid ).get_env (
69
67
"REECHO_VOICE_KEY" , None
70
68
)
71
- if (len (set (lang_kinds )) == 1 ) and (lang_kinds [0 ] in ["EN " ]):
69
+ if (len (set (lang_kinds )) == 1 ) and (lang_kinds [0 ] in ["en " ]):
72
70
voice_data = await request_en (message .text )
73
71
else :
74
72
voice_data = await request_cn (
0 commit comments