mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-24 16:13:54 +08:00
update:优化
This commit is contained in:
@@ -137,15 +137,16 @@ plugins:
|
|||||||
- ".wav"
|
- ".wav"
|
||||||
- ".p3"
|
- ".p3"
|
||||||
refresh_time: 300 # 刷新音乐列表的时间间隔,单位为秒
|
refresh_time: 300 # 刷新音乐列表的时间间隔,单位为秒
|
||||||
# 声纹识别配置
|
|
||||||
voiceprint:
|
# 声纹识别配置
|
||||||
# 声纹接口地址
|
voiceprint:
|
||||||
url:
|
# 声纹接口地址
|
||||||
# 说话人配置:speaker_id,名称,描述
|
url:
|
||||||
speakers:
|
# 说话人配置:speaker_id,名称,描述
|
||||||
- "test1,张三,张三是一个程序员"
|
speakers:
|
||||||
- "test2,李四,李四是一个产品经理"
|
- "test1,张三,张三是一个程序员"
|
||||||
- "test3,王五,王五是一个设计师"
|
- "test2,李四,李四是一个产品经理"
|
||||||
|
- "test3,王五,王五是一个设计师"
|
||||||
|
|
||||||
# #####################################################################################
|
# #####################################################################################
|
||||||
# ################################以下是角色模型配置######################################
|
# ################################以下是角色模型配置######################################
|
||||||
|
|||||||
@@ -136,7 +136,21 @@ async def send_stt_message(conn, text):
|
|||||||
return
|
return
|
||||||
|
|
||||||
"""发送 STT 状态消息"""
|
"""发送 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(
|
await conn.websocket.send(
|
||||||
json.dumps({"type": "stt", "text": stt_text, "session_id": conn.session_id})
|
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:
|
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({
|
return json.dumps({
|
||||||
"speaker": speaker_name,
|
"speaker": speaker_name,
|
||||||
"content": text
|
"content": text
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class Dialogue:
|
|||||||
# 添加说话人个性化描述
|
# 添加说话人个性化描述
|
||||||
try:
|
try:
|
||||||
config = load_config()
|
config = load_config()
|
||||||
voiceprint_config = config.get("plugins", {}).get("voiceprint", {})
|
voiceprint_config = config.get("voiceprint", {})
|
||||||
speakers = voiceprint_config.get("speakers", [])
|
speakers = voiceprint_config.get("speakers", [])
|
||||||
|
|
||||||
if 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"):
|
if voiceprint_config and voiceprint_config.get("url") and voiceprint_config.get("speakers"):
|
||||||
new_asr.init_voiceprint(voiceprint_config)
|
new_asr.init_voiceprint(voiceprint_config)
|
||||||
logger.bind(tag=TAG).info("ASR模块声纹识别功能已启用")
|
logger.bind(tag=TAG).info("ASR模块声纹识别功能已启用")
|
||||||
|
|||||||
@@ -118,8 +118,7 @@ class VoiceprintProvider:
|
|||||||
result_name = self.speaker_map[speaker_id]["name"]
|
result_name = self.speaker_map[speaker_id]["name"]
|
||||||
return result_name
|
return result_name
|
||||||
else:
|
else:
|
||||||
logger.bind(tag=TAG).warning(f"未识别的说话人ID: {speaker_id}")
|
return None
|
||||||
return "未知说话人"
|
|
||||||
else:
|
else:
|
||||||
logger.bind(tag=TAG).error(f"声纹识别API错误: HTTP {response.status}")
|
logger.bind(tag=TAG).error(f"声纹识别API错误: HTTP {response.status}")
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user