liumaolin
commited on
Commit
·
7cddb77
1
Parent(s):
d662661
增强性能日志记录功能,新增用户问题日志记录方法
Browse files- 在`PerformanceLogMixin`中添加`log_task_user_question`方法,用于记录用户提问的音频。
- 在`ASRWorker`类中集成该方法,以便在处理语音任务时记录用户问题。
- 移除`AudioStreamPlayer`类中的调试模式检查,确保性能日志始终记录音频播放任务。
src/voice_dialogue/services/audio/player.py
CHANGED
|
@@ -59,8 +59,7 @@ class AudioStreamPlayer(BaseThread, TaskStatusMixin, HistoryMixin, PerformanceLo
|
|
| 59 |
)
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
self.log_task_performance(voice_task, "音频播放")
|
| 64 |
|
| 65 |
self.update_chat_history(voice_task)
|
| 66 |
|
|
|
|
| 59 |
)
|
| 60 |
)
|
| 61 |
|
| 62 |
+
self.log_task_performance(voice_task, "音频播放")
|
|
|
|
| 63 |
|
| 64 |
self.update_chat_history(voice_task)
|
| 65 |
|
src/voice_dialogue/services/mixins.py
CHANGED
|
@@ -2,7 +2,7 @@ from collections import OrderedDict
|
|
| 2 |
|
| 3 |
from voice_dialogue.core.constants import (
|
| 4 |
voice_state_manager, session_manager, dropped_audio_cache,
|
| 5 |
-
user_still_speaking_event, chat_history_cache
|
| 6 |
)
|
| 7 |
from voice_dialogue.models.voice_task import VoiceTask
|
| 8 |
from voice_dialogue.utils.logger import logger
|
|
@@ -62,6 +62,9 @@ class PerformanceLogMixin:
|
|
| 62 |
|
| 63 |
def log_task_performance(self, voice_task: VoiceTask, task_name: str = "任务"):
|
| 64 |
"""记录ASR, LLM, TTS各阶段耗时和音频长度"""
|
|
|
|
|
|
|
|
|
|
| 65 |
try:
|
| 66 |
from voice_dialogue.services.utils import calculate_audio_duration
|
| 67 |
|
|
@@ -89,3 +92,16 @@ class PerformanceLogMixin:
|
|
| 89 |
)
|
| 90 |
except Exception as e:
|
| 91 |
logger.error(f"记录任务性能信息时出错: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
from voice_dialogue.core.constants import (
|
| 4 |
voice_state_manager, session_manager, dropped_audio_cache,
|
| 5 |
+
user_still_speaking_event, chat_history_cache, is_debug_mode
|
| 6 |
)
|
| 7 |
from voice_dialogue.models.voice_task import VoiceTask
|
| 8 |
from voice_dialogue.utils.logger import logger
|
|
|
|
| 62 |
|
| 63 |
def log_task_performance(self, voice_task: VoiceTask, task_name: str = "任务"):
|
| 64 |
"""记录ASR, LLM, TTS各阶段耗时和音频长度"""
|
| 65 |
+
if is_debug_mode():
|
| 66 |
+
return
|
| 67 |
+
|
| 68 |
try:
|
| 69 |
from voice_dialogue.services.utils import calculate_audio_duration
|
| 70 |
|
|
|
|
| 92 |
)
|
| 93 |
except Exception as e:
|
| 94 |
logger.error(f"记录任务性能信息时出错: {e}")
|
| 95 |
+
|
| 96 |
+
def log_task_user_question(self, voice_task: VoiceTask):
|
| 97 |
+
if is_debug_mode():
|
| 98 |
+
return
|
| 99 |
+
|
| 100 |
+
from voice_dialogue.config.paths import PROJECT_ROOT
|
| 101 |
+
output_path = PROJECT_ROOT / "output"
|
| 102 |
+
if not output_path.exists():
|
| 103 |
+
output_path.mkdir(parents=True, exist_ok=True)
|
| 104 |
+
|
| 105 |
+
import soundfile as sf
|
| 106 |
+
output_filename = output_path / (voice_task.id + ".wav")
|
| 107 |
+
sf.write(output_filename.as_posix(), voice_task.audio, 16000, subtype="PCM_16")
|
src/voice_dialogue/services/speech/recognizer.py
CHANGED
|
@@ -7,11 +7,12 @@ import numpy as np
|
|
| 7 |
from voice_dialogue.core.base import BaseThread
|
| 8 |
from voice_dialogue.core.constants import user_still_speaking_event, voice_state_manager, dropped_audio_cache
|
| 9 |
from voice_dialogue.models.voice_task import VoiceTask
|
|
|
|
| 10 |
from voice_dialogue.utils.cache import LRUCacheDict
|
| 11 |
from .recognizers import asr_manager
|
| 12 |
|
| 13 |
|
| 14 |
-
class ASRWorker(BaseThread):
|
| 15 |
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None,
|
| 16 |
user_voice_queue: Queue,
|
| 17 |
transcribed_text_queue: Queue,
|
|
@@ -37,6 +38,8 @@ class ASRWorker(BaseThread):
|
|
| 37 |
except Empty:
|
| 38 |
continue
|
| 39 |
|
|
|
|
|
|
|
| 40 |
voice_task.language = self.language
|
| 41 |
voice_task.whisper_start_time = time.time()
|
| 42 |
|
|
|
|
| 7 |
from voice_dialogue.core.base import BaseThread
|
| 8 |
from voice_dialogue.core.constants import user_still_speaking_event, voice_state_manager, dropped_audio_cache
|
| 9 |
from voice_dialogue.models.voice_task import VoiceTask
|
| 10 |
+
from voice_dialogue.services.mixins import PerformanceLogMixin
|
| 11 |
from voice_dialogue.utils.cache import LRUCacheDict
|
| 12 |
from .recognizers import asr_manager
|
| 13 |
|
| 14 |
|
| 15 |
+
class ASRWorker(BaseThread, PerformanceLogMixin):
|
| 16 |
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None,
|
| 17 |
user_voice_queue: Queue,
|
| 18 |
transcribed_text_queue: Queue,
|
|
|
|
| 38 |
except Empty:
|
| 39 |
continue
|
| 40 |
|
| 41 |
+
self.log_task_user_question(voice_task)
|
| 42 |
+
|
| 43 |
voice_task.language = self.language
|
| 44 |
voice_task.whisper_start_time = time.time()
|
| 45 |
|