File size: 545 Bytes
459ba07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)}