modify tts and txt
This commit is contained in:
parent
7cbe6d073b
commit
d08a74b4e4
@ -68,23 +68,24 @@ class TTSAudioSplitHandle(TTSAudioHandle):
|
|||||||
if not self._is_running:
|
if not self._is_running:
|
||||||
logger.info('TTSAudioSplitHandle::on_handle is not running')
|
logger.info('TTSAudioSplitHandle::on_handle is not running')
|
||||||
return
|
return
|
||||||
# heapq.heappush(self._priority_queue, (index, stream))
|
|
||||||
|
|
||||||
|
s, txt = stream
|
||||||
with self._lock:
|
with self._lock:
|
||||||
|
if len(self._priority_queue) != 0:
|
||||||
current = self._priority_queue[0][0]
|
current = self._priority_queue[0][0]
|
||||||
if current == 0:
|
if current == 0:
|
||||||
self._current = 0
|
self._current = 0
|
||||||
self._priority_queue.clear()
|
self._priority_queue.clear()
|
||||||
|
|
||||||
if stream is None:
|
if s is None:
|
||||||
heapq.heappush(self._priority_queue, (index, None))
|
heapq.heappush(self._priority_queue, (index, None))
|
||||||
else:
|
else:
|
||||||
stream_len = stream.shape[0]
|
stream_len = s.shape[0]
|
||||||
idx = 0
|
idx = 0
|
||||||
chunks = []
|
chunks = []
|
||||||
while stream_len >= self._chunk and self._is_running:
|
while stream_len >= self._chunk and self._is_running:
|
||||||
# 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])
|
chunks.append(s[idx:idx + self._chunk])
|
||||||
stream_len -= self._chunk
|
stream_len -= self._chunk
|
||||||
idx += self._chunk
|
idx += self._chunk
|
||||||
if not self._is_running:
|
if not self._is_running:
|
||||||
|
@ -46,11 +46,11 @@ class TTSBase(NLPCallback):
|
|||||||
t = time.time()
|
t = time.time()
|
||||||
stream = await self._on_request(txt)
|
stream = await self._on_request(txt)
|
||||||
if stream is None or self._is_running is False:
|
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
|
return
|
||||||
logger.info(f'-------tts time:{time.time() - t:.4f}s, txt:{txt}')
|
logger.info(f'-------tts time:{time.time() - t:.4f}s, txt:{txt}')
|
||||||
if self._handle is not None and self._is_running:
|
if self._handle is not None and self._is_running:
|
||||||
await self._on_handle(stream, index)
|
await self._on_handle((stream, txt), index)
|
||||||
else:
|
else:
|
||||||
logger.info(f'handle is None, running:{self._is_running}')
|
logger.info(f'handle is None, running:{self._is_running}')
|
||||||
|
|
||||||
|
@ -58,21 +58,22 @@ class TTSEdgeHttp(TTSBase):
|
|||||||
|
|
||||||
async def _on_handle(self, stream, index):
|
async def _on_handle(self, stream, index):
|
||||||
print('-------tts _on_handle')
|
print('-------tts _on_handle')
|
||||||
|
st, txt = stream
|
||||||
try:
|
try:
|
||||||
stream.seek(0)
|
st.seek(0)
|
||||||
byte_stream = self.__create_bytes_stream(stream)
|
byte_stream = self.__create_bytes_stream(st)
|
||||||
print('-------tts start push chunk', index)
|
print('-------tts start push chunk', index)
|
||||||
self._handle.on_handle(byte_stream, index)
|
self._handle.on_handle((byte_stream, txt), index)
|
||||||
stream.seek(0)
|
st.seek(0)
|
||||||
stream.truncate()
|
st.truncate()
|
||||||
print('-------tts finish push chunk')
|
print('-------tts finish push chunk')
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._handle.on_handle(None, index)
|
self._handle.on_handle(None, index)
|
||||||
stream.seek(0)
|
st.seek(0)
|
||||||
stream.truncate()
|
st.truncate()
|
||||||
print('-------tts finish error:', e)
|
print('-------tts finish error:', e)
|
||||||
stream.close()
|
st.close()
|
||||||
|
|
||||||
def __create_bytes_stream(self, byte_stream):
|
def __create_bytes_stream(self, byte_stream):
|
||||||
stream, sample_rate = sf.read(byte_stream) # [T*sample_rate,] float64
|
stream, sample_rate = sf.read(byte_stream) # [T*sample_rate,] float64
|
||||||
|
Loading…
Reference in New Issue
Block a user