mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-14 00:53:25 +00:00
feat: audio chat
This commit is contained in:
36
src/blackbox/audio_chat.py
Normal file
36
src/blackbox/audio_chat.py
Normal file
@ -0,0 +1,36 @@
|
||||
from fastapi import Request, Response,status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from .blackbox import Blackbox
|
||||
|
||||
class AudioChat(Blackbox):
|
||||
|
||||
def __init__(self, asr, gpt, tts):
|
||||
self.asr = asr
|
||||
self.gpt = gpt
|
||||
self.tts = tts
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self.processing(*args, **kwargs)
|
||||
|
||||
def valid(self, *args, **kwargs) -> bool :
|
||||
data = args[0]
|
||||
if isinstance(data, bytes):
|
||||
return True
|
||||
return False
|
||||
|
||||
async def processing(self, *args, **kwargs):
|
||||
data = args[0]
|
||||
text = await self.asr(data)
|
||||
# TODO: ID
|
||||
text = self.gpt("123", " " + text)
|
||||
audio = self.tts(text)
|
||||
return audio
|
||||
|
||||
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()
|
||||
by = await self.processing(d)
|
||||
return Response(content=by.read(), media_type="audio/wav", headers={"Content-Disposition": "attachment; filename=audio.wav"})
|
||||
Reference in New Issue
Block a user