bugfix
This commit is contained in:
parent
61ecdfea36
commit
6f06b223a2
@ -1,3 +1,4 @@
|
|||||||
|
import base64
|
||||||
from appPublic.log import info, debug, warning, error, exception, critical
|
from appPublic.log import info, debug, warning, error, exception, critical
|
||||||
from appPublic.dictObject import DictObject
|
from appPublic.dictObject import DictObject
|
||||||
from ahserver.serverenv import ServerEnv
|
from ahserver.serverenv import ServerEnv
|
||||||
@ -7,11 +8,38 @@ async def generate(request, **kw):
|
|||||||
params_kw = kw.get('params_kw', DictObject())
|
params_kw = kw.get('params_kw', DictObject())
|
||||||
info(f'{params_kw=}')
|
info(f'{params_kw=}')
|
||||||
model = params_kw.model
|
model = params_kw.model
|
||||||
|
audiob64 = params_kw.audiob64
|
||||||
|
if audiob64 is None:
|
||||||
|
return {
|
||||||
|
'status':'error',
|
||||||
|
'message':'audio is null'
|
||||||
|
}
|
||||||
engine = None
|
engine = None
|
||||||
g = ServerEnv()
|
g = ServerEnv()
|
||||||
if model=='whisper':
|
if model=='whisper':
|
||||||
engine = g.whisper_engine
|
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()
|
resp = StreamResponse()
|
||||||
await resp.prepare(request)
|
await resp.prepare(request)
|
||||||
line = await request.content.readline()
|
line = await request.content.readline()
|
||||||
@ -28,4 +56,3 @@ async def generate(request, **kw):
|
|||||||
info('response finish')
|
info('response finish')
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,5 +42,5 @@ class WhisperBase64(WhisperBase):
|
|||||||
def _stt(self, audio_base64):
|
def _stt(self, audio_base64):
|
||||||
raw = base64.decode(audio_base64)
|
raw = base64.decode(audio_base64)
|
||||||
ndarr = np.frombuffer(raw, dtype=np.float32)
|
ndarr = np.frombuffer(raw, dtype=np.float32)
|
||||||
return self.model.transcribe(raw)
|
return self.model.transcribe(ndarr)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user