mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
Server runtime: - translate model-visible strings: direct_answer tool schema, web_search tool desc/errors/results, call_device tool desc/replies, hass_state desc/report strings; they were Chinese text fed to LLMs and devices - replace Chinese pconline geocoder with ip-api.com (English city names) - prompt_manager: drop dead Chinese WEEKDAY_MAP, stop forcing lang=zh_CN for weather, English fallback location - delete orphan alibl_endpoint.py (no importers after AliBL removal) and dead initialize_voiceprint() calling a nonexistent ASR hook - translate mcp_server_settings.json descriptors - test_current_time: assert English weekday/date behavior (upstream test still expected Chinese weekdays) Docs/branding: - README and docs/guides/voiceprint.md: voiceprint IS implemented via the HTTP VoiceprintProvider; document the real protocol (health/identify) and privacy notes instead of falsely claiming the feature is missing - issue templates: English Ops: - Dockerfile-server-base: drop Aliyun PyPI mirror from published image - LICENSE: keep xinnan-tech copyright notice alongside downstream (MIT) - CI: run westernization_audit as a gate; make smoke test failure fatal - westernization.md: point python verification at the real pytest layout
131 lines
4.2 KiB
Python
131 lines
4.2 KiB
Python
from typing import Dict, Any
|
|
from config.logger import setup_logging
|
|
from core.utils import tts, llm, intent, memory, vad, asr
|
|
|
|
TAG = __name__
|
|
logger = setup_logging()
|
|
|
|
|
|
def initialize_modules(
|
|
logger,
|
|
config: Dict[str, Any],
|
|
init_vad=False,
|
|
init_asr=False,
|
|
init_llm=False,
|
|
init_tts=False,
|
|
init_memory=False,
|
|
init_intent=False,
|
|
) -> Dict[str, Any]:
|
|
"""
|
|
Initialize all module components
|
|
|
|
Args:
|
|
config: Configuration dictionary
|
|
|
|
Returns:
|
|
Dict[str, Any]: Dictionary containing all initialized modules
|
|
"""
|
|
modules = {}
|
|
|
|
# Initialize TTS module
|
|
if init_tts:
|
|
select_tts_module = config["selected_module"]["TTS"]
|
|
modules["tts"] = initialize_tts(config)
|
|
logger.bind(tag=TAG).info(f"Component initialized: tts successful {select_tts_module}")
|
|
|
|
# Initialize LLM module
|
|
if init_llm:
|
|
select_llm_module = config["selected_module"]["LLM"]
|
|
llm_type = (
|
|
select_llm_module
|
|
if "type" not in config["LLM"][select_llm_module]
|
|
else config["LLM"][select_llm_module]["type"]
|
|
)
|
|
modules["llm"] = llm.create_instance(
|
|
llm_type,
|
|
config["LLM"][select_llm_module],
|
|
)
|
|
logger.bind(tag=TAG).info(f"Component initialized: llm successful {select_llm_module}")
|
|
|
|
# Initialize Intent module
|
|
if init_intent:
|
|
select_intent_module = config["selected_module"]["Intent"]
|
|
intent_type = (
|
|
select_intent_module
|
|
if "type" not in config["Intent"][select_intent_module]
|
|
else config["Intent"][select_intent_module]["type"]
|
|
)
|
|
modules["intent"] = intent.create_instance(
|
|
intent_type,
|
|
config["Intent"][select_intent_module],
|
|
)
|
|
logger.bind(tag=TAG).info(f"Component initialized: intent successful {select_intent_module}")
|
|
|
|
# Initialize Memory module
|
|
if init_memory:
|
|
select_memory_module = config["selected_module"]["Memory"]
|
|
memory_type = (
|
|
select_memory_module
|
|
if "type" not in config["Memory"][select_memory_module]
|
|
else config["Memory"][select_memory_module]["type"]
|
|
)
|
|
modules["memory"] = memory.create_instance(
|
|
memory_type,
|
|
config["Memory"][select_memory_module],
|
|
config.get("summaryMemory", None),
|
|
)
|
|
logger.bind(tag=TAG).info(f"Component initialized: memory successful {select_memory_module}")
|
|
|
|
# Initialize VAD module
|
|
if init_vad:
|
|
select_vad_module = config["selected_module"]["VAD"]
|
|
vad_type = (
|
|
select_vad_module
|
|
if "type" not in config["VAD"][select_vad_module]
|
|
else config["VAD"][select_vad_module]["type"]
|
|
)
|
|
modules["vad"] = vad.create_instance(
|
|
vad_type,
|
|
config["VAD"][select_vad_module],
|
|
)
|
|
logger.bind(tag=TAG).info(f"Component initialized: vad successful {select_vad_module}")
|
|
|
|
# Initialize ASR module
|
|
if init_asr:
|
|
select_asr_module = config["selected_module"]["ASR"]
|
|
modules["asr"] = initialize_asr(config)
|
|
logger.bind(tag=TAG).info(f"Component initialized: asr successful {select_asr_module}")
|
|
return modules
|
|
|
|
|
|
def initialize_tts(config):
|
|
select_tts_module = config["selected_module"]["TTS"]
|
|
tts_config = config["TTS"][select_tts_module].copy()
|
|
tts_config.setdefault("tts_timeout", config.get("tts_timeout", 15))
|
|
tts_type = (
|
|
select_tts_module
|
|
if "type" not in tts_config
|
|
else tts_config["type"]
|
|
)
|
|
new_tts = tts.create_instance(
|
|
tts_type,
|
|
tts_config,
|
|
str(config.get("delete_audio", True)).lower() in ("true", "1", "yes"),
|
|
)
|
|
return new_tts
|
|
|
|
|
|
def initialize_asr(config):
|
|
select_asr_module = config["selected_module"]["ASR"]
|
|
asr_type = (
|
|
select_asr_module
|
|
if "type" not in config["ASR"][select_asr_module]
|
|
else config["ASR"][select_asr_module]["type"]
|
|
)
|
|
new_asr = asr.create_instance(
|
|
asr_type,
|
|
config["ASR"][select_asr_module],
|
|
str(config.get("delete_audio", True)).lower() in ("true", "1", "yes"),
|
|
)
|
|
logger.bind(tag=TAG).info("ASR module initialization completed")
|
|
return new_asr
|