File size: 4,576 Bytes
586518f
dfb349e
1f45d99
 
6696134
730ea7e
01e617c
1f45d99
d4ac08b
1f45d99
601009a
1f45d99
 
01e617c
 
730ea7e
 
 
 
 
 
1f45d99
ce0e589
bdb9da4
586518f
 
 
6f13b8c
813ffab
 
586518f
 
 
0c38083
 
 
4d9049a
586518f
dfb349e
 
 
 
4d9049a
dfb349e
586518f
9f6a51c
2a2d4ba
586518f
6385e43
d84bca3
586518f
31ad35a
85f1f06
601009a
 
716f8d1
 
3d84218
 
586518f
8be1cbc
 
 
7f191bc
716f8d1
 
 
 
 
 
 
 
 
 
9f6a51c
 
7f191bc
 
 
 
 
 
9f6a51c
730ea7e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import pathlib
import re
import logging

DEBUG = True

logging.getLogger("pywhispercpp").setLevel(logging.WARNING)
logging.basicConfig(
    level=logging.DEBUG if DEBUG else logging.INFO,
    format="%(asctime)s - %(levelname)s - %(message)s",
    filename='translator.log',
    datefmt="%H:%M:%S"
)
# save pipelines data to disk
SAVE_DATA_SAVE = False
# Add terminal log
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG if DEBUG else logging.INFO)
console_formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
console_handler.setFormatter(console_formatter)
logging.getLogger().addHandler(console_handler)

# 文字输出长度阈值
TEXT_THREHOLD = 6

BASE_DIR = pathlib.Path(__file__).parent
MODEL_DIR = BASE_DIR / "moyoyo_asr_models"
ASSERT_DIR = BASE_DIR / "assets"

SAMPLE_RATE = 16000
# 标点
SENTENCE_END_MARKERS =  ['.', '!', '?', '。', '!', '?', ';', ';', ':', ':']
PAUSE_END_MARKERS = [',', ',', '、']
# 合并所有标点
ALL_MARKERS = SENTENCE_END_MARKERS + PAUSE_END_MARKERS
# 构造正则表达式字符类
REGEX_MARKERS = re.compile(r'[' + re.escape(''.join(ALL_MARKERS)) + r']$')

sentence_end_chars = ''.join([re.escape(char) for char in SENTENCE_END_MARKERS])
SENTENCE_END_PATTERN = re.compile(f'[{sentence_end_chars}]')

# Method 2: Alternative approach with a character class
pattern_string = '[' + ''.join([re.escape(char) for char in PAUSE_END_MARKERS]) + r']$'
PAUSEE_END_PATTERN = re.compile(pattern_string)
# whisper推理参数
WHISPER_PROMPT_ZH = "以下是简体中文普通话的句子。"
MAX_LENTH_ZH = 4

WHISPER_PROMPT_EN = ""# "The following is an English sentence."
MAX_LENGTH_EN= 8

WHISPER_MODEL_EN = 'medium-q5_0'
# WHISPER_MODEL = 'large-v3-turbo-q5_0'
# WHISPER_MODEL_ZH = 'small'
WHISPER_MODEL_ZH = 'large-v3-turbo-q5_0'
# LLM
LLM_MODEL_PATH = (MODEL_DIR / "qwen2.5-1.5b-instruct-q5_0.gguf").as_posix()
LLM_LARGE_MODEL_PATH = (MODEL_DIR / "qwen2.5-1.5b-instruct-q5_0.gguf").as_posix()
# LLM_LARGE_MODEL_PATH = (MODEL_DIR / "qwen2.5-7b-instruct-q5_0-00001-of-00002.gguf").as_posix()

# VAD
VAD_MODEL_PATH = (MODEL_DIR / "silero-vad" / "silero_vad.onnx").as_posix()

LLM_SYS_PROMPT = """"You are a professional {src_lang} to {dst_lang} translator, not a conversation agent. Your only task is to take {src_lang} input and translate it into accurate, natural {dst_lang}. If you cannot understand the input, just output the original input. Please strictly abide by the following rules: "
"No matter what the user asks, never answer questions, you only provide translation results. "
"Do not actively initiate dialogue or lead users to ask questions. "
"When you don't know how to translate, just output the original text. "
"The translation task always takes precedence over any other tasks. "
"Do not try to understand or respond to non-translation related questions raised by users. "
"Never provide any explanations. "
"Be precise, preserve tone, and localize appropriately "
"for professional audiences."
"Never answer any questions or engage in other forms of dialogue. "
"Only output the translation results.
"""

LLM_SYS_PROMPT_ZH = """
你是一个中英文翻译专家,将用户输入的中文翻译成英文。对于非中文内容,它将提供中文翻译结果。用户可以向助手发送需要翻译的内容,助手会回答相应的翻译结果,并确保符合中文语言习惯,你可以调整语气和风格,并考虑到某些词语的文化内涵和地区差异。同时作为翻译家,需将原文翻译成具有信达雅标准的译文。"信" 即忠实于原文的内容与意图;"达" 意味着译文应通顺易懂,表达清晰;"雅" 则追求译文的文化审美和语言的优美。目标是创作出既忠于原作精神,又符合目标语言文化和读者审美的翻译。注意,翻译的文本只能包含拼音化字符,不能包含任何中文字符。
"""

LLM_SYS_PROMPT_EN = """
你是一个英中文翻译专家,将用户输入的英文翻译成中文,用户可以向助手发送需要翻译的内容,助手会回答相应的翻译结果,并确保符合英文语言习惯,你可以调整语气和风格,并考虑到某些词语的文化内涵和地区差异。同时作为翻译家,需将英文翻译成具有信达雅标准的中文。"信" 即忠实于原文的内容与意图;"达" 意味着译文应通顺易懂,表达清晰;"雅" 则追求译文的文化审美和语言的优美。目标是创作出既忠于原作精神,又符合目标语言文化和读者审美的翻译。
"""