bark / handler.py
MrJohnSandoval's picture
Create handler.py
459ba07 verified
Raw History Blame
545 Bytes
from typing import Dict, Any
from transformers import pipeline
class EndpointHandler():
def __init__(self, path: str = ""):
self.pipe = pipeline("text-to-speech", model="suno/bark", device=0)
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
inputs = data.pop("inputs", data)
try:
audio = self.pipe(inputs)
return {
"audio": audio.tolist(),
"sampling_rate": 24000
}
except Exception as e:
return {"error": str(e)}