mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-14 00:53:25 +00:00
refactor: relocate asr model
This commit is contained in:
41
src/blackbox/asr.py
Normal file
41
src/blackbox/asr.py
Normal file
@ -0,0 +1,41 @@
|
||||
from io import BytesIO
|
||||
from typing import Any, Coroutine
|
||||
|
||||
from fastapi import Request, Response, status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from ..asr.rapid_paraformer.utils import read_yaml
|
||||
from ..asr.rapid_paraformer import RapidParaformer
|
||||
from .blackbox import Blackbox
|
||||
|
||||
class ASR(Blackbox):
|
||||
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
config = read_yaml(args[0])
|
||||
self.paraformer = RapidParaformer(config)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self.processing(*args, **kwargs)
|
||||
|
||||
async def processing(self, *args, **kwargs):
|
||||
data = args[0]
|
||||
results = self.paraformer([BytesIO(data)])
|
||||
if len(results) == 0:
|
||||
return None
|
||||
return results[0]
|
||||
|
||||
def valid(self, data: any) -> bool:
|
||||
if isinstance(data, bytes):
|
||||
return True
|
||||
return False
|
||||
|
||||
async def fast_api_handler(self, request: Request) -> Response:
|
||||
data = (await request.form()).get("audio")
|
||||
if data is None:
|
||||
return JSONResponse(content={"error": "data is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
d = await data.read()
|
||||
try:
|
||||
txt = await self.processing(d)
|
||||
except ValueError as e:
|
||||
return JSONResponse(content={"error": str(e)}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
return JSONResponse(content={"txt": txt}, status_code=status.HTTP_200_OK)
|
||||
@ -1,7 +1,7 @@
|
||||
from .sum import SUM
|
||||
from .sentiment import Sentiment
|
||||
from .tts import TTS
|
||||
from ..asr.asr import ASR
|
||||
from .asr import ASR
|
||||
from .audio_to_text import AudioToText
|
||||
from .blackbox import Blackbox
|
||||
from .calculator import Calculator
|
||||
|
||||
@ -23,7 +23,6 @@ class Tesou(Blackbox):
|
||||
"user_id": id,
|
||||
"prompt": prompt,
|
||||
}
|
||||
print(message)
|
||||
response = requests.post(url, json=message)
|
||||
return response.json()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user