liumaolin
commited on
Commit
·
02c321c
1
Parent(s):
b636027
重构`is_task_interrupted`方法以检查语音任务中断状态
Browse files- 添加`is_task_interrupted`方法,简化语音任务中断检查逻辑,提高代码可读性。
- 更新相关逻辑以使用新方法替代原有的中断检查方式。
src/voice_dialogue/services/audio/player.py
CHANGED
|
@@ -47,7 +47,7 @@ class AudioStreamPlayer(BaseThread):
|
|
| 47 |
user_still_speaking_event.clear()
|
| 48 |
break
|
| 49 |
|
| 50 |
-
if
|
| 51 |
break
|
| 52 |
|
| 53 |
if voice_task.session_id != session_manager.current_id:
|
|
@@ -87,6 +87,19 @@ class AudioStreamPlayer(BaseThread):
|
|
| 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
|
|
|
|
| 47 |
user_still_speaking_event.clear()
|
| 48 |
break
|
| 49 |
|
| 50 |
+
if self.is_task_interrupted(voice_task):
|
| 51 |
break
|
| 52 |
|
| 53 |
if voice_task.session_id != session_manager.current_id:
|
|
|
|
| 87 |
|
| 88 |
break
|
| 89 |
|
| 90 |
+
def is_task_interrupted(self, voice_task: VoiceTask) -> bool:
|
| 91 |
+
"""
|
| 92 |
+
检查语音任务是否被中断
|
| 93 |
+
|
| 94 |
+
Args:
|
| 95 |
+
voice_task: 当前处理的语音任务
|
| 96 |
+
|
| 97 |
+
Returns:
|
| 98 |
+
bool: 如果任务被中断返回True,否则返回False
|
| 99 |
+
"""
|
| 100 |
+
return (voice_state_manager.interrupt_task_id and
|
| 101 |
+
voice_task.id != voice_state_manager.interrupt_task_id)
|
| 102 |
+
|
| 103 |
def _log_task_info(self, voice_task):
|
| 104 |
import librosa
|
| 105 |
asr_duration = voice_task.whisper_end_time - voice_task.whisper_start_time
|