modify tts audio handle
This commit is contained in:
parent
48d0a7d05d
commit
6b5361d91a
@ -14,7 +14,7 @@ class TTSAudioHandle(AudioHandler):
|
||||
def __init__(self, context, handler):
|
||||
super().__init__(context, handler)
|
||||
self._sample_rate = 16000
|
||||
self._index = 1
|
||||
self._index = -1
|
||||
|
||||
@property
|
||||
def sample_rate(self):
|
||||
@ -41,20 +41,33 @@ class TTSAudioSplitHandle(TTSAudioHandle):
|
||||
self.sample_rate = self._context.sample_rate
|
||||
self._chunk = self.sample_rate // self._context.fps
|
||||
self._priority_queue = []
|
||||
self._current = 0
|
||||
logger.info("TTSAudioSplitHandle init")
|
||||
|
||||
def on_handle(self, stream, index):
|
||||
# heapq.heappush(self._priority_queue, (index, stream))
|
||||
if stream is None:
|
||||
heapq.heappush(self._priority_queue, (index, None))
|
||||
|
||||
else:
|
||||
stream_len = stream.shape[0]
|
||||
idx = 0
|
||||
|
||||
chunks = []
|
||||
while stream_len >= self._chunk:
|
||||
self.on_next_handle(stream[idx:idx + self._chunk], 0)
|
||||
# self.on_next_handle(stream[idx:idx + self._chunk], 0)
|
||||
chunks.append(stream[idx:idx + self._chunk])
|
||||
stream_len -= self._chunk
|
||||
idx += self._chunk
|
||||
heapq.heappush(self._priority_queue, (index, chunks))
|
||||
current = self._priority_queue[0][0]
|
||||
print('TTSAudioSplitHandle::on_handle', index, current, self._current)
|
||||
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):
|
||||
pass
|
||||
|
@ -45,11 +45,15 @@ class TTSBase(NLPCallback):
|
||||
self.message(txt)
|
||||
|
||||
def message(self, txt):
|
||||
txt = txt.strip()
|
||||
if len(txt) == 0:
|
||||
logger.info(f'message is empty')
|
||||
return
|
||||
logger.info(f'message:{txt}')
|
||||
print(f'message:{txt}')
|
||||
index = 0
|
||||
if self._handle is not None:
|
||||
index = self._handle.get_index()
|
||||
print(f'message txt-index:{txt}, index {index}')
|
||||
self._message_queue.add_task(self._request, txt, index)
|
||||
|
||||
def stop(self):
|
||||
|
5
ui.py
5
ui.py
@ -37,7 +37,7 @@ class App(customtkinter.CTk):
|
||||
|
||||
# configure window
|
||||
self.title("TTS demo")
|
||||
self.geometry(f"{1100}x{580}")
|
||||
self.geometry(f"{1150}x{580}")
|
||||
|
||||
self.grid_columnconfigure(1, weight=1)
|
||||
self.grid_rowconfigure((0, 1), weight=1)
|
||||
@ -88,7 +88,7 @@ class App(customtkinter.CTk):
|
||||
self._canvas.pack(fill=customtkinter.BOTH, expand=customtkinter.YES)
|
||||
|
||||
def _render(self):
|
||||
after_time = 29
|
||||
after_time = 24
|
||||
try:
|
||||
image = self._queue.get(block=True, timeout=0.003)
|
||||
if image is None:
|
||||
@ -155,7 +155,6 @@ class App(customtkinter.CTk):
|
||||
|
||||
def on_render(self, image):
|
||||
self._queue.put(image)
|
||||
print('on_render', self._queue.qsize())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user