modify tts logs

This commit is contained in:
brige 2024-11-14 19:14:22 +08:00
parent 742340971b
commit 88a307ed6a
2 changed files with 8 additions and 6 deletions

View File

@ -38,21 +38,21 @@ class TTSBase(NLPCallback):
self._handle = value self._handle = value
async def _request(self, txt: str, index): async def _request(self, txt: str, index):
# print('_request:', txt)
if not self._is_running: if not self._is_running:
logger.info('TTSBase::_request is not running') logger.info('TTSBase::_request is not running')
return return
t = time.time() t = time.time()
stream = await self._on_request(txt) stream = await self._on_request(txt)
logger.info(f'-------tts request time:{time.time() - t:.4f}s, txt:{txt}')
if stream is None or self._is_running is False: if stream is None or self._is_running is False:
logger.warning(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}')
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, txt), 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}')
logger.info(f'-------tts finish time:{time.time() - t:.4f}s, txt:{txt}')
async def _on_request(self, text: str): async def _on_request(self, text: str):
pass pass

View File

@ -1,5 +1,6 @@
#encoding = utf8 #encoding = utf8
import logging import logging
import time
from io import BytesIO from io import BytesIO
import aiohttp import aiohttp
@ -57,22 +58,23 @@ class TTSEdgeHttp(TTSBase):
return self._on_sync_request(data) return self._on_sync_request(data)
async def _on_handle(self, stream, index): async def _on_handle(self, stream, index):
print('-------tts _on_handle')
st, txt = stream st, txt = stream
try: try:
st.seek(0) st.seek(0)
t = time.time()
byte_stream = self.__create_bytes_stream(st) byte_stream = self.__create_bytes_stream(st)
print('-------tts start push chunk', index) logger.info(f'-------tts resample time:{time.time() - t:.4f}s, txt:{txt}')
t = time.time()
self._handle.on_handle((byte_stream, txt), index) self._handle.on_handle((byte_stream, txt), index)
logger.info(f'-------tts handle time:{time.time() - t:.4f}s')
st.seek(0) st.seek(0)
st.truncate() st.truncate()
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)
st.seek(0) st.seek(0)
st.truncate() st.truncate()
print('-------tts finish error:', e) logger.error(f'-------tts finish error:{e}')
st.close() st.close()
def __create_bytes_stream(self, byte_stream): def __create_bytes_stream(self, byte_stream):