Files changed (2) hide show
  1. handler.py +31 -0
  2. requirements.txt +3 -0
handler.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # handler.py
2
+
3
+ from typing import Dict, Any
4
+ from transformers import pipeline
5
+
6
+ class EndpointHandler:
7
+ def __init__(self, model_path: str = ""):
8
+ """
9
+ Load the MMS-TTS pipeline once at startup.
10
+ transformers>=4.33.0 is required for MMS-TTS support.
11
+ """
12
+ self.tts = pipeline(
13
+ task="text-to-speech",
14
+ model=model_path,
15
+ device=0,
16
+ # device_map="auto" # optional: to leverage GPU if available
17
+ )
18
+
19
+ def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
20
+ """
21
+ data: {"inputs": "<text to synthesize>"}
22
+ Returns: {"wav": <binary audio>, "sampling_rate": <int>}
23
+ """
24
+ text = data.get("inputs", "")
25
+ # Run TTS; returns a dict with "wav" and "sampling_rate"
26
+ result = self.tts(text)
27
+ audio = result["audio"]
28
+ return {
29
+ "array": audio.T.tolist(), # transpose if needed to fix ushort format:contentReference[oaicite:6]{index=6}
30
+ "sampling_rate": result["sampling_rate"],
31
+ }
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers>=4.33.0 # MMS-TTS support
2
+ torch # if not already included
3
+ # any other libs you need