32 lines
826 B
Python
32 lines
826 B
Python
from ahserver.serverenv import ServerEnv
|
|
from aiohttp.web import StreamResponse
|
|
|
|
from whisper.load_model import WhisperBase64
|
|
|
|
async def generate(request, **kw):
|
|
model = kw.get('model', 'whisper')
|
|
engine = None
|
|
g = ServerEnv()
|
|
if model=='whisper':
|
|
engine = g.whisper_engine
|
|
if engine is None:
|
|
engine = WhisperBase64
|
|
g.whisper_engine = engine
|
|
|
|
await resp.prepare(request)
|
|
line = await request.content.readline()
|
|
content = ''
|
|
while line:
|
|
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()
|
|
return resp
|
|
|
|
rf = RegisterFunction()
|
|
rf.register('generate', generate)
|
|
|