From d08a74b4e4f0969bb1ba81182084d46cec9534a3 Mon Sep 17 00:00:00 2001 From: jiegeaiai Date: Tue, 12 Nov 2024 23:07:55 +0800 Subject: [PATCH] modify tts and txt --- tts/tts_audio_handle.py | 17 +++++++++-------- tts/tts_base.py | 4 ++-- tts/tts_edge_http.py | 17 +++++++++-------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/tts/tts_audio_handle.py b/tts/tts_audio_handle.py index a70c239..5c5d193 100644 --- a/tts/tts_audio_handle.py +++ b/tts/tts_audio_handle.py @@ -68,23 +68,24 @@ class TTSAudioSplitHandle(TTSAudioHandle): if not self._is_running: logger.info('TTSAudioSplitHandle::on_handle is not running') return - # heapq.heappush(self._priority_queue, (index, stream)) + s, txt = stream with self._lock: - current = self._priority_queue[0][0] - if current == 0: - self._current = 0 - self._priority_queue.clear() + if len(self._priority_queue) != 0: + current = self._priority_queue[0][0] + if current == 0: + self._current = 0 + self._priority_queue.clear() - if stream is None: + if s is None: heapq.heappush(self._priority_queue, (index, None)) else: - stream_len = stream.shape[0] + stream_len = s.shape[0] idx = 0 chunks = [] while stream_len >= self._chunk and self._is_running: # self.on_next_handle(stream[idx:idx + self._chunk], 0) - chunks.append(stream[idx:idx + self._chunk]) + chunks.append(s[idx:idx + self._chunk]) stream_len -= self._chunk idx += self._chunk if not self._is_running: diff --git a/tts/tts_base.py b/tts/tts_base.py index d6e21a3..80c2711 100644 --- a/tts/tts_base.py +++ b/tts/tts_base.py @@ -46,11 +46,11 @@ class TTSBase(NLPCallback): t = time.time() stream = await self._on_request(txt) if stream is None or self._is_running is False: - logger.warn(f'-------stream is None or is_running {self._is_running}') + logger.warning(f'-------stream is None or is_running {self._is_running}') return logger.info(f'-------tts time:{time.time() - t:.4f}s, txt:{txt}') if self._handle is not None and self._is_running: - await self._on_handle(stream, index) + await self._on_handle((stream, txt), index) else: logger.info(f'handle is None, running:{self._is_running}') diff --git a/tts/tts_edge_http.py b/tts/tts_edge_http.py index 4856039..aa7eb20 100644 --- a/tts/tts_edge_http.py +++ b/tts/tts_edge_http.py @@ -58,21 +58,22 @@ class TTSEdgeHttp(TTSBase): async def _on_handle(self, stream, index): print('-------tts _on_handle') + st, txt = stream try: - stream.seek(0) - byte_stream = self.__create_bytes_stream(stream) + st.seek(0) + byte_stream = self.__create_bytes_stream(st) print('-------tts start push chunk', index) - self._handle.on_handle(byte_stream, index) - stream.seek(0) - stream.truncate() + self._handle.on_handle((byte_stream, txt), index) + st.seek(0) + st.truncate() print('-------tts finish push chunk') except Exception as e: self._handle.on_handle(None, index) - stream.seek(0) - stream.truncate() + st.seek(0) + st.truncate() print('-------tts finish error:', e) - stream.close() + st.close() def __create_bytes_stream(self, byte_stream): stream, sample_rate = sf.read(byte_stream) # [T*sample_rate,] float64