asr/app/asr_engine.py

28 lines
766 B
Python
Raw Normal View History

2024-08-03 18:22:53 +08:00
from appPublic.log import info, debug, warning, error, exception, critical
2024-08-03 17:27:14 +08:00
from ahserver.serverenv import ServerEnv
from aiohttp.web import StreamResponse
async def generate(request, **kw):
model = kw.get('model', 'whisper')
engine = None
g = ServerEnv()
if model=='whisper':
engine = g.whisper_engine
await resp.prepare(request)
line = await request.content.readline()
content = ''
while line:
2024-08-03 18:22:53 +08:00
info(f'read from request stream {line=}')
2024-08-03 17:27:14 +08:00
txt = await engine.stt(line)
content += txt
d = json.dumps({'content':content})
btxt = d.encode('utf8')
await resp.write(btxt)
await resp.drain()
line = await request.content.readline()
2024-08-03 18:22:53 +08:00
info('response finish')
2024-08-03 17:27:14 +08:00
return resp