white
commited on
Create handler.py
Browse files- handler.py +16 -0
handler.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import base64
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class TTSHandler:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.pipe = pipeline("text-to-speech", model="suno/bark")
|
| 8 |
+
|
| 9 |
+
def preprocess(self, text):
|
| 10 |
+
return {"inputs": text.strip()}
|
| 11 |
+
|
| 12 |
+
def inference(self, inputs):
|
| 13 |
+
return self.pipe(**inputs)
|
| 14 |
+
|
| 15 |
+
def postprocess(self, audio):
|
| 16 |
+
return {"audio": base64.b64encode(audio).decode("utf-8")}
|