liumaolin
commited on
Commit
·
29766c6
1
Parent(s):
9c5ad6e
Add session validation checks to `player.py` and `generator.py`
Browse files- Ensure voice tasks are processed only for the current session by comparing `session_id`.
- Break or skip processing if the session ID mismatches.
src/voice_dialogue/services/audio/generator.py
CHANGED
|
@@ -3,7 +3,8 @@ from multiprocessing import Queue
|
|
| 3 |
from queue import Empty
|
| 4 |
|
| 5 |
from voice_dialogue.core.base import BaseThread
|
| 6 |
-
from voice_dialogue.core.constants import dropped_audio_cache, user_still_speaking_event, voice_state_manager
|
|
|
|
| 7 |
from voice_dialogue.models.voice_task import VoiceTask
|
| 8 |
from .generators import tts_manager, BaseTTSConfig
|
| 9 |
|
|
@@ -79,6 +80,9 @@ class TTSAudioGenerator(BaseThread):
|
|
| 79 |
if voice_task.id != voice_state_manager.interrupt_task_id:
|
| 80 |
continue
|
| 81 |
|
|
|
|
|
|
|
|
|
|
| 82 |
voice_task.tts_start_time = time.time()
|
| 83 |
tts_generated_sentence_audio = self.tts_instance.synthesize(voice_task.answer_sentence)
|
| 84 |
voice_task.tts_generated_sentence_audio = tts_generated_sentence_audio
|
|
|
|
| 3 |
from queue import Empty
|
| 4 |
|
| 5 |
from voice_dialogue.core.base import BaseThread
|
| 6 |
+
from voice_dialogue.core.constants import dropped_audio_cache, user_still_speaking_event, voice_state_manager, \
|
| 7 |
+
session_manager
|
| 8 |
from voice_dialogue.models.voice_task import VoiceTask
|
| 9 |
from .generators import tts_manager, BaseTTSConfig
|
| 10 |
|
|
|
|
| 80 |
if voice_task.id != voice_state_manager.interrupt_task_id:
|
| 81 |
continue
|
| 82 |
|
| 83 |
+
if voice_task.session_id != session_manager.current_id:
|
| 84 |
+
continue
|
| 85 |
+
|
| 86 |
voice_task.tts_start_time = time.time()
|
| 87 |
tts_generated_sentence_audio = self.tts_instance.synthesize(voice_task.answer_sentence)
|
| 88 |
voice_task.tts_generated_sentence_audio = tts_generated_sentence_audio
|
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
|
| 13 |
)
|
| 14 |
from voice_dialogue.models.voice_task import VoiceTask, AnswerDisplayMessage
|
| 15 |
from voice_dialogue.utils.logger import logger
|
|
@@ -50,6 +50,9 @@ class AudioStreamPlayer(BaseThread):
|
|
| 50 |
if task_id != voice_state_manager.interrupt_task_id:
|
| 51 |
break
|
| 52 |
|
|
|
|
|
|
|
|
|
|
| 53 |
if answer_id in dropped_audio_cache:
|
| 54 |
# print('Drop answer audio')
|
| 55 |
break
|
|
|
|
| 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
|
|
|
|
| 50 |
if task_id != voice_state_manager.interrupt_task_id:
|
| 51 |
break
|
| 52 |
|
| 53 |
+
if voice_task.session_id != session_manager.current_id:
|
| 54 |
+
break
|
| 55 |
+
|
| 56 |
if answer_id in dropped_audio_cache:
|
| 57 |
# print('Drop answer audio')
|
| 58 |
break
|