liumaolin commited on
Commit
e0f42b2
·
1 Parent(s): 2291ed2

Enable debug mode with global configuration and detailed task logging when active

Browse files
main.py CHANGED
@@ -45,6 +45,7 @@ if lib_path.exists() and lib_path.as_posix() not in sys.path:
45
  sys.path.insert(0, lib_path.as_posix())
46
 
47
  from voice_dialogue.core.launcher import launch_system
 
48
  from voice_dialogue.cli.args import create_argument_parser
49
  from voice_dialogue.api.server import launch_api_server
50
 
@@ -62,11 +63,14 @@ def main():
62
  parser = create_argument_parser()
63
  args = parser.parse_args()
64
 
 
 
65
  print(f"""
66
  {"=" * 80}
67
  VoiceDialogue - 语音对话系统
68
  {"=" * 80}
69
  运行模式: {args.mode.upper()}
 
70
  {"=" * 80}
71
  """)
72
 
 
45
  sys.path.insert(0, lib_path.as_posix())
46
 
47
  from voice_dialogue.core.launcher import launch_system
48
+ from voice_dialogue.core.constants import set_debug_mode
49
  from voice_dialogue.cli.args import create_argument_parser
50
  from voice_dialogue.api.server import launch_api_server
51
 
 
63
  parser = create_argument_parser()
64
  args = parser.parse_args()
65
 
66
+ set_debug_mode(args.debug)
67
+
68
  print(f"""
69
  {"=" * 80}
70
  VoiceDialogue - 语音对话系统
71
  {"=" * 80}
72
  运行模式: {args.mode.upper()}
73
+ 调试模式: {'启用' if args.debug else '禁用'}
74
  {"=" * 80}
75
  """)
76
 
src/voice_dialogue/cli/args.py CHANGED
@@ -47,6 +47,13 @@ def create_argument_parser():
47
  help='运行模式: cli=命令行模式, api=API服务器模式 (默认: cli)'
48
  )
49
 
 
 
 
 
 
 
 
50
  # 命令行模式参数
51
  cli_group = parser.add_argument_group('命令行模式参数')
52
  cli_group.add_argument(
 
47
  help='运行模式: cli=命令行模式, api=API服务器模式 (默认: cli)'
48
  )
49
 
50
+ parser.add_argument(
51
+ '--debug',
52
+ action='store_true',
53
+ default=False,
54
+ help='启动debug模式'
55
+ )
56
+
57
  # 命令行模式参数
58
  cli_group = parser.add_argument_group('命令行模式参数')
59
  cli_group.add_argument(
src/voice_dialogue/core/constants.py CHANGED
@@ -7,6 +7,20 @@ from voice_dialogue.utils.cache import LRUCacheDict
7
  from .session_manager import SessionIdManager
8
  from .state_manager import VoiceStateManager
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # ======================= 音频配置常量 =======================
11
 
12
  # 音频采样率与窗口大小映射配置
 
7
  from .session_manager import SessionIdManager
8
  from .state_manager import VoiceStateManager
9
 
10
+ # ======================= 应用配置常量 =======================
11
+
12
+ # 全局调试模式状态
13
+ DEBUG_MODE = False
14
+
15
+ def set_debug_mode(enabled: bool):
16
+ """设置全局调试模式"""
17
+ global DEBUG_MODE
18
+ DEBUG_MODE = enabled
19
+
20
+ def is_debug_mode() -> bool:
21
+ """检查是否启用了调试模式"""
22
+ return DEBUG_MODE
23
+
24
  # ======================= 音频配置常量 =======================
25
 
26
  # 音频采样率与窗口大小映射配置
src/voice_dialogue/services/audio/player.py CHANGED
@@ -9,7 +9,7 @@ from playsound import playsound
9
  from voice_dialogue.core.base import BaseThread
10
  from voice_dialogue.core.constants import (
11
  user_still_speaking_event, voice_state_manager, dropped_audio_cache, chat_history_cache,
12
- silence_over_threshold_event, session_manager
13
  )
14
  from voice_dialogue.models.voice_task import VoiceTask, AnswerDisplayMessage
15
  from voice_dialogue.utils.logger import logger
@@ -70,26 +70,8 @@ class AudioStreamPlayer(BaseThread):
70
  )
71
  )
72
 
73
- # import librosa
74
- # asr_duration = voice_task.whisper_end_time - voice_task.whisper_start_time
75
- # llm_duration = voice_task.llm_end_time - voice_task.llm_start_time
76
- # tts_duration = voice_task.tts_end_time - voice_task.tts_start_time
77
- # audio_data, sample_rate = voice_task.tts_generated_sentence_audio
78
- # audio_duration = librosa.get_duration(y=audio_data, sr=sample_rate)
79
- #
80
- # logger.info(
81
- # f"\n"
82
- # f"┌───────────────────────── 任务信息 ───────────────────────┐\n"
83
- # f"│ 任务ID: {voice_task.id}\n"
84
- # f"├───────────────────────── 性能统计 ────────────────────────┤\n"
85
- # f"│ ASR 耗时: {asr_duration:.2f}s\n"
86
- # f"│ LLM 耗时: {llm_duration:.2f}s\n"
87
- # f"│ TTS 耗时: {tts_duration:.2f}s\n"
88
- # f"│ 音频长度: {audio_duration:.2f}s\n"
89
- # f"├───────────────────────── 生成内容 ────────────────────────┤\n"
90
- # f"│-> {voice_task.answer_sentence}\n"
91
- # f"└──────────────────────────────────────────────────────────┘"
92
- # )
93
 
94
  self.update_chat_history(voice_task)
95
 
@@ -105,6 +87,27 @@ class AudioStreamPlayer(BaseThread):
105
 
106
  break
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  def update_chat_history(self, voice_task):
109
  chat_history = chat_history_cache.get(voice_task.session_id, OrderedDict())
110
  task_answer_id = voice_task.answer_id
 
9
  from voice_dialogue.core.base import BaseThread
10
  from voice_dialogue.core.constants import (
11
  user_still_speaking_event, voice_state_manager, dropped_audio_cache, chat_history_cache,
12
+ silence_over_threshold_event, session_manager, is_debug_mode
13
  )
14
  from voice_dialogue.models.voice_task import VoiceTask, AnswerDisplayMessage
15
  from voice_dialogue.utils.logger import logger
 
70
  )
71
  )
72
 
73
+ if is_debug_mode():
74
+ self._log_task_info(voice_task)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  self.update_chat_history(voice_task)
77
 
 
87
 
88
  break
89
 
90
+ def _log_task_info(self, voice_task):
91
+ import librosa
92
+ asr_duration = voice_task.whisper_end_time - voice_task.whisper_start_time
93
+ llm_duration = voice_task.llm_end_time - voice_task.llm_start_time
94
+ tts_duration = voice_task.tts_end_time - voice_task.tts_start_time
95
+ audio_data, sample_rate = voice_task.tts_generated_sentence_audio
96
+ audio_duration = librosa.get_duration(y=audio_data, sr=sample_rate)
97
+ logger.info(
98
+ f"\n"
99
+ f"┌───────────────────────── 任务信息 ───────────────────────┐\n"
100
+ f"│ 任务ID: {voice_task.id}\n"
101
+ f"├───────────────────────── 性能统计 ────────────────────────┤\n"
102
+ f"│ ASR 耗时: {asr_duration:.2f}s\n"
103
+ f"│ LLM 耗时: {llm_duration:.2f}s\n"
104
+ f"│ TTS 耗时: {tts_duration:.2f}s\n"
105
+ f"│ 音频长度: {audio_duration:.2f}s\n"
106
+ f"├───────────────────────── 生成内容 ────────────────────────┤\n"
107
+ f"│-> {voice_task.answer_sentence}\n"
108
+ f"└──────────────────────────────────────────────────────────┘"
109
+ )
110
+
111
  def update_chat_history(self, voice_task):
112
  chat_history = chat_history_cache.get(voice_task.session_id, OrderedDict())
113
  task_answer_id = voice_task.answer_id