Commit
·
696efb5
1
Parent(s):
abcc982
Adds custom handler
Browse files- .python-version +1 -0
- handler.py +28 -0
- requirements.txt +1 -0
.python-version
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
3.9
|
handler.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from TTS.tts.configs.xtts_config import XttsConfig
|
2 |
+
from TTS.tts.models.xtts import Xtts
|
3 |
+
from typing import Dict, List, Any
|
4 |
+
|
5 |
+
available_speakers = ['Claribel Dervla', 'Daisy Studious', 'Gracie Wise', 'Tammie Ema', 'Alison Dietlinde', 'Ana Florence', 'Annmarie Nele', 'Asya Anara', 'Brenda Stern', 'Gitta Nikolina', 'Henriette Usha', 'Sofia Hellen', 'Tammy Grit', 'Tanja Adelina', 'Vjollca Johnnie', 'Andrew Chipper', 'Badr Odhiambo', 'Dionisio Schuyler', 'Royston Min', 'Viktor Eka', 'Abrahan Mack', 'Adde Michal', 'Baldur Sanjin', 'Craig Gutsy', 'Damien Black', 'Gilberto Mathias', 'Ilkin Urbano', 'Kazuhiko Atallah', 'Ludvig Milivoj', 'Suad Qasim', 'Torcull Diarmuid', 'Viktor Menelaos', 'Zacharie Aimilios', 'Nova Hogarth', 'Maja Ruoho', 'Uta Obando', 'Lidiya Szekeres', 'Chandra MacFarland', 'Szofi Granger', 'Camilla Holmström', 'Lilya Stainthorpe', 'Zofija Kendrick', 'Narelle Moon', 'Barbora MacLean', 'Alexandra Hisakawa', 'Alma María', 'Rosemary Okafor', 'Ige Behringer', 'Filip Traverse', 'Damjan Chapman', 'Wulf Carlevaro', 'Aaron Dreschner', 'Kumar Dahl', 'Eugenio Mataracı', 'Ferran Simen', 'Xavier Hayasaka', 'Luis Moray', 'Marcos Rudaski']
|
6 |
+
|
7 |
+
class EndpointHandler:
|
8 |
+
def __init__(self, path=""):
|
9 |
+
config = XttsConfig()
|
10 |
+
config.load_json(path + "/config.json")
|
11 |
+
self.model = Xtts.init_from_config(config)
|
12 |
+
self.model.load_checkpoint(config, checkpoint_dir=path, eval=True)
|
13 |
+
self.model.cuda()
|
14 |
+
|
15 |
+
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
16 |
+
text = data['inputs']
|
17 |
+
speaker = data.get('speaker', None)
|
18 |
+
speaker_wav = data.get('speaker_wav', None)
|
19 |
+
if speaker is not None:
|
20 |
+
if speaker in available_speakers:
|
21 |
+
#speaker_wav = f"/path/to/{speaker}.wav"
|
22 |
+
outputs = self.model.synthesize(text, config, speaker=speaker, gpt_cond_len=3, language="en")
|
23 |
+
# Save or process the outputs as needed
|
24 |
+
return outputs
|
25 |
+
else:
|
26 |
+
return "Invalid speaker specified."
|
27 |
+
|
28 |
+
return "No speaker specified."
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
TTS
|