This commit is contained in:
yumoqing 2024-08-04 17:34:16 +08:00
parent 61ecdfea36
commit 6f06b223a2
2 changed files with 29 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import base64
from appPublic.log import info, debug, warning, error, exception, critical
from appPublic.dictObject import DictObject
from ahserver.serverenv import ServerEnv
@ -7,11 +8,38 @@ async def generate(request, **kw):
params_kw = kw.get('params_kw', DictObject())
info(f'{params_kw=}')
model = params_kw.model
audiob64 = params_kw.audiob64
if audiob64 is None:
return {
'status':'error',
'message':'audio is null'
}
engine = None
g = ServerEnv()
if model=='whisper':
engine = g.whisper_engine
if engine is None:
retrun {
'status':'error',
'message':f'model={model} is not defined'
}
try:
txt = await engine.stt(audiob64)
info(f'{audiob64=}, {txt=}')
return {
"status':'ok',
"content':txt
}
except Exception as e:
exception(f'{e}')
print_exc()
return {
'status':'error',
'message':f'{e}'
}
async def streaming(request, **kw):
resp = StreamResponse()
await resp.prepare(request)
line = await request.content.readline()
@ -28,4 +56,3 @@ async def generate(request, **kw):
info('response finish')
return resp

View File

@ -42,5 +42,5 @@ class WhisperBase64(WhisperBase):
def _stt(self, audio_base64):
raw = base64.decode(audio_base64)
ndarr = np.frombuffer(raw, dtype=np.float32)
return self.model.transcribe(raw)
return self.model.transcribe(ndarr)