Spaces:
Running on Zero
Running on Zero
Create handler.py
Browse filesAdd custom handler for SUNO Bark TTS model inference endpoint. This handler implements text-to-speech capabilities with GPU acceleration and proper error handling, returning audio arrays with 24kHz sampling rate.
- handler.py +17 -0
handler.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Any
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
class EndpointHandler():
|
| 5 |
+
def __init__(self, path: str = ""):
|
| 6 |
+
self.pipe = pipeline("text-to-speech", model="suno/bark", device=0)
|
| 7 |
+
|
| 8 |
+
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
| 9 |
+
inputs = data.pop("inputs", data)
|
| 10 |
+
try:
|
| 11 |
+
audio = self.pipe(inputs)
|
| 12 |
+
return {
|
| 13 |
+
"audio": audio.tolist(),
|
| 14 |
+
"sampling_rate": 24000
|
| 15 |
+
}
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return {"error": str(e)}
|