mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-14 00:53:25 +00:00
feat: tts
This commit is contained in:
@ -8,7 +8,7 @@ class Blackbox(ABC):
|
||||
the methods processing, valid and fast_api_handler.
|
||||
If implemented correctly, the blackbox class can be used in the main.py file
|
||||
"""
|
||||
def __init__(self, config: any) -> None:
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
pass
|
||||
|
||||
"""
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
from .tts import TTS
|
||||
from ..asr.asr import ASR
|
||||
from .audio_to_text import AudioToText
|
||||
from .blackbox import Blackbox
|
||||
@ -8,8 +9,8 @@ from .text_to_audio import TextToAudio
|
||||
class BlackboxFactory:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.tts = TTS()
|
||||
self.asr = ASR("./.env.yaml")
|
||||
pass
|
||||
|
||||
def create_blackbox(self, blackbox_name: str, blackbox_config: dict) -> Blackbox:
|
||||
if blackbox_name == "audio_to_text":
|
||||
@ -20,4 +21,6 @@ class BlackboxFactory:
|
||||
return Calculator(blackbox_config)
|
||||
if blackbox_name == "asr":
|
||||
return self.asr
|
||||
if blackbox_name == "tts":
|
||||
return self.tts
|
||||
raise ValueError("Invalid blockbox type")
|
||||
36
src/blackbox/tts.py
Normal file
36
src/blackbox/tts.py
Normal file
@ -0,0 +1,36 @@
|
||||
import io
|
||||
from typing import Any, Coroutine
|
||||
|
||||
from fastapi import Request, Response, status
|
||||
from fastapi.responses import JSONResponse
|
||||
from .blackbox import Blackbox
|
||||
from tts.tts_service import TTService
|
||||
|
||||
class TTS(Blackbox):
|
||||
|
||||
def __init__(self) -> None:
|
||||
config = {
|
||||
'paimon': ['resources/tts/models/paimon6k.json', 'resources/tts/models/paimon6k_390k.pth', 'character_paimon', 1],
|
||||
'yunfei': ['resources/tts/models/yunfeimix2.json', 'resources/tts/models/yunfeimix2_53k.pth', 'character_yunfei', 1.1],
|
||||
'catmaid': ['resources/tts/models/catmix.json', 'resources/tts/models/catmix_107k.pth', 'character_catmaid', 1.2]
|
||||
}
|
||||
self.tts_service = TTService(*config['catmaid'])
|
||||
super().__init__(config)
|
||||
|
||||
def processing(self, text: str) -> io.BytesIO:
|
||||
audio = self.tts_service.read(text)
|
||||
return audio
|
||||
|
||||
def valid(self, txt: any) -> bool:
|
||||
return isinstance(txt, str)
|
||||
|
||||
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/wav", headers={"Content-Disposition": "attachment; filename=audio.wav"})
|
||||
Reference in New Issue
Block a user