mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-15 17:43:25 +00:00
Blackbox MeloTTS created
This commit is contained in:
47
src/blackbox/melotts.py
Normal file
47
src/blackbox/melotts.py
Normal file
@ -0,0 +1,47 @@
|
||||
import io
|
||||
import time
|
||||
|
||||
import requests
|
||||
from fastapi import Request, Response, status
|
||||
from fastapi.responses import JSONResponse
|
||||
from injector import inject
|
||||
from injector import singleton
|
||||
|
||||
from ..configuration import MeloConf
|
||||
from .blackbox import Blackbox
|
||||
|
||||
|
||||
@singleton
|
||||
class MeloTTS(Blackbox):
|
||||
melotts: str
|
||||
|
||||
@inject
|
||||
def __init__(self, melo_config: MeloConf) -> None:
|
||||
self.melotts = melo_config.melotts
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self.processing(*args, **kwargs)
|
||||
|
||||
def valid(self, *args, **kwargs) -> bool:
|
||||
text = args[0]
|
||||
return isinstance(text, str)
|
||||
|
||||
def processing(self, *args, **kwargs) -> io.BytesIO:
|
||||
text = args[0]
|
||||
current_time = time.time()
|
||||
audio = self.tts_service.read(text)
|
||||
print("#### MeloTTS Service consume : ", (time.time()-current_time))
|
||||
return audio
|
||||
|
||||
async def fast_api_handler(self, request: Request) -> Response:
|
||||
try:
|
||||
data = await request.json()
|
||||
except:
|
||||
return JSONResponse(content={"error": "json parse error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
text = data.get("text")
|
||||
if text is None:
|
||||
return JSONResponse(content={"error": "text is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
by = self.processing(text)
|
||||
return Response(content=by.read(), media_type="audio/mp3", headers={"Content-Disposition": "attachment; filename=audio.mp3"})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user