fastwhisper/app/fastwhisper.py
2025-11-06 11:09:47 +08:00

42 lines
1.0 KiB
Python

import asyncio
from appPublic.worker import get_event_loop
from appPublic.log import debug
from fw.init import load_fastwhisper
from ahserver.webapp import webapp
from ahserver.serverenv import ServerEnv
from appPublic.registerfunction import RegisterFunction
async def transcribe(request, *args, **kw):
env = request._run_ns
ret = await env.fastwhisper.submit_task(env.params_kw)
return ret
async def get_status(request, *args, **kw):
env = request._run_ns
ret = await env.fastwhisper.get_status(env.params_kw.task_id)
return ret
async def start_fw_server(*args, **kw):
debug(f'start fastwhisper engine, {args=}, {kw=}')
env = ServerEnv()
asyncio.create_task(env.fastwhisper.run())
debug('fastwhisper engine started ')
async def ahapp_built(app):
env = ServerEnv()
app.on_startup.append(start_fw_server)
def init():
rf = RegisterFunction()
rf.register('transcribe', transcribe)
rf.register('ahapp_built', ahapp_built)
rf.register('get_status', get_status)
load_fastwhisper()
if __name__ == '__main__':
loop = get_event_loop()
webapp(init)