From dde41769bf1841b1eb1511efce6f157d6d3c586b Mon Sep 17 00:00:00 2001 From: brige Date: Sun, 10 Nov 2024 14:06:47 +0800 Subject: [PATCH] modify abort tts hangle --- tts/tts_audio_handle.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tts/tts_audio_handle.py b/tts/tts_audio_handle.py index b64ca95..35b9b9e 100644 --- a/tts/tts_audio_handle.py +++ b/tts/tts_audio_handle.py @@ -69,6 +69,13 @@ class TTSAudioSplitHandle(TTSAudioHandle): logger.info('TTSAudioSplitHandle::on_handle is not running') return # heapq.heappush(self._priority_queue, (index, stream)) + + with self._lock: + current = self._priority_queue[0][0] + if current == 0: + self._current = 0 + self._priority_queue.clear() + if stream is None: heapq.heappush(self._priority_queue, (index, None)) else: @@ -84,19 +91,15 @@ class TTSAudioSplitHandle(TTSAudioHandle): return heapq.heappush(self._priority_queue, (index, chunks)) - with self._lock: - current = self._priority_queue[0][0] - if current == 0: - self._current = 0 - print('TTSAudioSplitHandle::on_handle', index, current, self._current, len(self._priority_queue)) - if current == self._current: - self._current = self._current + 1 - chunks = heapq.heappop(self._priority_queue)[1] - if chunks is None: - pass - else: - for chunk in chunks: - self.on_next_handle(chunk, 0) + print('TTSAudioSplitHandle::on_handle', index, current, self._current, len(self._priority_queue)) + if current == self._current: + self._current = self._current + 1 + chunks = heapq.heappop(self._priority_queue)[1] + if chunks is None: + pass + else: + for chunk in chunks: + self.on_next_handle(chunk, 0) def stop(self): self._is_running = False