Skip to content

Patch #420 #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions llmkira/extra/voice_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,32 @@
from llmkira.task.schema import EventMessage, Location


def check_string(text):
def detect_text(text: str) -> list:
"""
检查字符串是否 TTS 可以处理
:param text: 字符串
:return: 是否符合要求
检测文本的语言
:param text: 文本
:return: 语言
"""
text = text.replace("\n", "")
text = text[:200]
parsed_text = detect_multilingual(text)
if not parsed_text:
return False
return []
lang_kinds = []
for lang in parsed_text:
lang_kinds.append(lang.get("lang", "ru"))
lang_ = lang.get("lang", None)
if lang_:
lang_kinds.append(lang_)
return lang_kinds


def check_string(text):
"""
检查字符串是否 TTS 可以处理
:param text: 字符串
:return: 是否符合要求
"""
lang_kinds = detect_text(text)
limit = 200
if len(set(lang_kinds)) == 1:
if lang_kinds[0] in ["en"]:
Expand Down Expand Up @@ -57,12 +71,7 @@ async def hook_run(self, *args, **kwargs):
for message in messages:
if not check_string(message.text):
return args, kwargs
parsed_text = detect_multilingual(message.text)
if not parsed_text:
return args, kwargs
lang_kinds = []
for lang in parsed_text:
lang_kinds.append(lang.get("lang"))
lang_kinds = detect_text(message.text)
reecho_api_key = await EnvManager(locate.uid).get_env(
"REECHO_VOICE_KEY", None
)
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ dependencies = [
"shortuuid<2.0.0,>=1.0.11",
"contextvars<3.0,>=2.4",
"pytz<2024.0.0,>=2023.3.post1",
"fasttext-wheel<1.0.0,>=0.9.2",
"tenacity<9.0.0,>=8.2.3",
"pysocks<2.0.0,>=1.7.1",
"flask-sqlalchemy<4.0.0,>=3.1.1",
Expand Down Expand Up @@ -53,7 +52,7 @@ dependencies = [
"apscheduler>=3.10.4",
"montydb[lmdb]>=2.5.2",
"pymongo>=4.6.3",
"fast-langdetect>=0.1.1",
"fast-langdetect>=0.2.1",
"lmdb>=1.4.1",
"e2b>=0.14.14",
"e2b-code-interpreter>=0.0.3",
Expand Down
Loading