update:优化

This commit is contained in:
3030332422
2025-07-09 14:23:47 +08:00
parent 5c83d63fe2
commit d13fb73c67
6 changed files with 29 additions and 15 deletions
+10 -9
View File
@@ -137,15 +137,16 @@ plugins:
- ".wav"
- ".p3"
refresh_time: 300 # 刷新音乐列表的时间间隔,单位为秒
# 声纹识别配置
voiceprint:
# 声纹接口地址
url:
# 说话人配置:speaker_id,名称,描述
speakers:
- "test1,张三,张三是一个程序员"
- "test2,李四,李四是一个产品经理"
- "test3,王五,王五是一个设计师"
# 声纹识别配置
voiceprint:
# 声纹接口地址
url:
# 说话人配置:speaker_id,名称,描述
speakers:
- "test1,张三,张三是一个程序员"
- "test2,李四,李四是一个产品经理"
- "test3,王五,王五是一个设计师"
# #####################################################################################
# ################################以下是角色模型配置######################################
@@ -136,7 +136,21 @@ async def send_stt_message(conn, text):
return
"""发送 STT 状态消息"""
stt_text = get_string_no_punctuation_or_emoji(text)
# 解析JSON格式,提取实际的用户说话内容
display_text = text
try:
# 尝试解析JSON格式
if text.strip().startswith('{') and text.strip().endswith('}'):
parsed_data = json.loads(text)
if isinstance(parsed_data, dict) and "content" in parsed_data:
# 如果是包含说话人信息的JSON格式,只显示content部分
display_text = parsed_data["content"]
except (json.JSONDecodeError, TypeError):
# 如果不是JSON格式,直接使用原始文本
display_text = text
stt_text = get_string_no_punctuation_or_emoji(display_text)
await conn.websocket.send(
json.dumps({"type": "stt", "text": stt_text, "session_id": conn.session_id})
)
@@ -192,7 +192,7 @@ class ASRProviderBase(ABC):
def _build_enhanced_text(self, text: str, speaker_name: Optional[str]) -> str:
"""构建包含说话人信息的文本"""
if speaker_name:
if speaker_name and speaker_name.strip():
return json.dumps({
"speaker": speaker_name,
"content": text
+1 -1
View File
@@ -84,7 +84,7 @@ class Dialogue:
# 添加说话人个性化描述
try:
config = load_config()
voiceprint_config = config.get("plugins", {}).get("voiceprint", {})
voiceprint_config = config.get("voiceprint", {})
speakers = voiceprint_config.get("speakers", [])
if speakers:
@@ -127,7 +127,7 @@ def initialize_asr(config):
)
# 初始化声纹识别功能
voiceprint_config = config.get("plugins", {}).get("voiceprint")
voiceprint_config = config.get("voiceprint")
if voiceprint_config and voiceprint_config.get("url") and voiceprint_config.get("speakers"):
new_asr.init_voiceprint(voiceprint_config)
logger.bind(tag=TAG).info("ASR模块声纹识别功能已启用")
@@ -118,8 +118,7 @@ class VoiceprintProvider:
result_name = self.speaker_map[speaker_id]["name"]
return result_name
else:
logger.bind(tag=TAG).warning(f"未识别的说话人ID: {speaker_id}")
return "未知说话人"
return None
else:
logger.bind(tag=TAG).error(f"声纹识别API错误: HTTP {response.status}")
return None