|
|
|
@ -120,7 +120,7 @@ class ConnectionHandler:
|
|
|
|
|
|
|
|
|
|
# 认证通过,继续处理
|
|
|
|
|
self.websocket = ws
|
|
|
|
|
self.session_id = str(uuid.uuid4())
|
|
|
|
|
self.session_id = str(uuid.uuid4()) # 会话ID是随机生成的
|
|
|
|
|
|
|
|
|
|
self.welcome_msg = self.config["xiaozhi"]
|
|
|
|
|
self.welcome_msg["session_id"] = self.session_id
|
|
|
|
@ -218,42 +218,53 @@ class ConnectionHandler:
|
|
|
|
|
False,
|
|
|
|
|
False,
|
|
|
|
|
)
|
|
|
|
|
'''
|
|
|
|
|
VAD,也就是语音端点检测技术,是Voice Activity Detection的缩写.
|
|
|
|
|
这个技术的主要任务是从带有噪声的语音中准确的定位出语音的开始和结束点,因为语音中含有很长的静音,
|
|
|
|
|
也就是把静音和实际语音分离开来,因为是语音数据的原始处理,所以VAD是语音信号处理过程的关键技术之一。
|
|
|
|
|
'''
|
|
|
|
|
if private_config.get("VAD", None) is not None:
|
|
|
|
|
init_vad = True
|
|
|
|
|
self.config["VAD"] = private_config["VAD"]
|
|
|
|
|
self.config["selected_module"]["VAD"] = private_config["selected_module"][
|
|
|
|
|
"VAD"
|
|
|
|
|
]
|
|
|
|
|
# 语音识别
|
|
|
|
|
if private_config.get("ASR", None) is not None:
|
|
|
|
|
init_asr = True
|
|
|
|
|
self.config["ASR"] = private_config["ASR"]
|
|
|
|
|
self.config["selected_module"]["ASR"] = private_config["selected_module"][
|
|
|
|
|
"ASR"
|
|
|
|
|
]
|
|
|
|
|
# 大模型
|
|
|
|
|
if private_config.get("LLM", None) is not None:
|
|
|
|
|
init_llm = True
|
|
|
|
|
self.config["LLM"] = private_config["LLM"]
|
|
|
|
|
self.config["selected_module"]["LLM"] = private_config["selected_module"][
|
|
|
|
|
"LLM"
|
|
|
|
|
]
|
|
|
|
|
# 语音合成
|
|
|
|
|
if private_config.get("TTS", None) is not None:
|
|
|
|
|
init_tts = True
|
|
|
|
|
self.config["TTS"] = private_config["TTS"]
|
|
|
|
|
self.config["selected_module"]["TTS"] = private_config["selected_module"][
|
|
|
|
|
"TTS"
|
|
|
|
|
]
|
|
|
|
|
# 记忆化
|
|
|
|
|
if private_config.get("Memory", None) is not None:
|
|
|
|
|
init_memory = True
|
|
|
|
|
self.config["Memory"] = private_config["Memory"]
|
|
|
|
|
self.config["selected_module"]["Memory"] = private_config[
|
|
|
|
|
"selected_module"
|
|
|
|
|
]["Memory"]
|
|
|
|
|
# 意图识别
|
|
|
|
|
if private_config.get("Intent", None) is not None:
|
|
|
|
|
init_intent = True
|
|
|
|
|
self.config["Intent"] = private_config["Intent"]
|
|
|
|
|
self.config["selected_module"]["Intent"] = private_config[
|
|
|
|
|
"selected_module"
|
|
|
|
|
]["Intent"]
|
|
|
|
|
# 默认提示词
|
|
|
|
|
if private_config.get("prompt", None) is not None:
|
|
|
|
|
self.config["prompt"] = private_config["prompt"]
|
|
|
|
|
try:
|
|
|
|
@ -281,15 +292,17 @@ class ConnectionHandler:
|
|
|
|
|
|
|
|
|
|
def _initialize_memory(self):
|
|
|
|
|
"""初始化记忆模块"""
|
|
|
|
|
device_id = self.headers.get("device-id", None)
|
|
|
|
|
device_id = self.headers.get("device-id", None) # 在headers中获取设备id
|
|
|
|
|
self.memory.init_memory(device_id, self.llm)
|
|
|
|
|
|
|
|
|
|
def _initialize_intent(self):
|
|
|
|
|
# 意图识别模式为function_call
|
|
|
|
|
if (
|
|
|
|
|
self.config["Intent"][self.config["selected_module"]["Intent"]]["type"]
|
|
|
|
|
== "function_call"
|
|
|
|
|
):
|
|
|
|
|
self.use_function_call_mode = True
|
|
|
|
|
|
|
|
|
|
"""初始化意图识别模块"""
|
|
|
|
|
# 获取意图识别配置
|
|
|
|
|
intent_config = self.config["Intent"]
|
|
|
|
@ -341,9 +354,7 @@ class ConnectionHandler:
|
|
|
|
|
m.content = prompt
|
|
|
|
|
|
|
|
|
|
def chat(self, query):
|
|
|
|
|
|
|
|
|
|
self.dialogue.put(Message(role="user", content=query))
|
|
|
|
|
|
|
|
|
|
response_message = []
|
|
|
|
|
processed_chars = 0 # 跟踪已处理的字符位置
|
|
|
|
|
try:
|
|
|
|
|