modify abort
This commit is contained in:
parent
3334918ed1
commit
a6153b1eb9
@ -3,6 +3,7 @@ import heapq
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
from eventbus import EventBus
|
from eventbus import EventBus
|
||||||
from utils import save_wav
|
from utils import save_wav
|
||||||
@ -28,7 +29,7 @@ class TTSAudioHandle(AudioHandler):
|
|||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
def on_clear_cache(self, *args, **kwargs):
|
def on_clear_cache(self, *args, **kwargs):
|
||||||
pass
|
self._index = -1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sample_rate(self):
|
def sample_rate(self):
|
||||||
@ -58,6 +59,7 @@ class TTSAudioSplitHandle(TTSAudioHandle):
|
|||||||
self.sample_rate = self._context.sample_rate
|
self.sample_rate = self._context.sample_rate
|
||||||
self._chunk = self.sample_rate // self._context.fps
|
self._chunk = self.sample_rate // self._context.fps
|
||||||
self._priority_queue = []
|
self._priority_queue = []
|
||||||
|
self._lock = Lock()
|
||||||
self._current = 0
|
self._current = 0
|
||||||
self._is_running = True
|
self._is_running = True
|
||||||
logger.info("TTSAudioSplitHandle init")
|
logger.info("TTSAudioSplitHandle init")
|
||||||
@ -81,26 +83,35 @@ class TTSAudioSplitHandle(TTSAudioHandle):
|
|||||||
if not self._is_running:
|
if not self._is_running:
|
||||||
return
|
return
|
||||||
heapq.heappush(self._priority_queue, (index, chunks))
|
heapq.heappush(self._priority_queue, (index, chunks))
|
||||||
current = self._priority_queue[0][0]
|
|
||||||
print('TTSAudioSplitHandle::on_handle', index, current, self._current, len(self._priority_queue))
|
with self._lock:
|
||||||
if current == self._current:
|
current = self._priority_queue[0][0]
|
||||||
self._current = self._current + 1
|
if current == 0:
|
||||||
chunks = heapq.heappop(self._priority_queue)[1]
|
self._current = 0
|
||||||
if chunks is None:
|
print('TTSAudioSplitHandle::on_handle', index, current, self._current, len(self._priority_queue))
|
||||||
pass
|
if current == self._current:
|
||||||
else:
|
self._current = self._current + 1
|
||||||
for chunk in chunks:
|
chunks = heapq.heappop(self._priority_queue)[1]
|
||||||
self.on_next_handle(chunk, 0)
|
if chunks is None:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
for chunk in chunks:
|
||||||
|
self.on_next_handle(chunk, 0)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._is_running = False
|
self._is_running = False
|
||||||
|
|
||||||
def on_clear_cache(self, *args, **kwargs):
|
def on_clear_cache(self, *args, **kwargs):
|
||||||
|
super().on_clear_cache()
|
||||||
if self._priority_queue is None or len(self._priority_queue) == 0:
|
if self._priority_queue is None or len(self._priority_queue) == 0:
|
||||||
return
|
return
|
||||||
current = self._priority_queue[0][0]
|
|
||||||
|
with self._lock:
|
||||||
|
print('TTSAudioSplitHandle::on_clear_cache', self._current)
|
||||||
|
self._current = 0
|
||||||
|
print('TTSAudioSplitHandle::on_clear_cache', self._current)
|
||||||
|
|
||||||
self._priority_queue.clear()
|
self._priority_queue.clear()
|
||||||
self._current = current
|
|
||||||
|
|
||||||
|
|
||||||
class TTSAudioSaveHandle(TTSAudioHandle):
|
class TTSAudioSaveHandle(TTSAudioHandle):
|
||||||
|
Loading…
Reference in New Issue
Block a user