Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,50 @@
|
|
1 |
-
from os import getenv
|
2 |
-
from huggingface_hub import hf_hub_download
|
3 |
-
from json import load as json_load , dump as json_dump
|
4 |
-
from torch import device as Device
|
5 |
-
from torch.cuda import is_available as cuda_is_available
|
6 |
-
from TTS.utils.synthesizer import Synthesizer
|
7 |
-
|
8 |
-
lang_conf = {
|
9 |
-
"as": "Assamese - অসমীয়া",
|
10 |
-
"bn": "Bangla - বাংলা",
|
11 |
-
"brx": "Boro - बड़ो",
|
12 |
-
"en": "English (Indian accent)",
|
13 |
-
"en+hi": "English+Hindi (Hinglish code-mixed)",
|
14 |
-
"gu": "Gujarati - ગુજરાતી",
|
15 |
-
"hi": "Hindi - हिंदी",
|
16 |
-
"kn": "Kannada - ಕನ್ನಡ",
|
17 |
-
"ml": "Malayalam - മലയാളം",
|
18 |
-
"mni": "Manipuri - মিতৈলোন",
|
19 |
-
"mr": "Marathi - मराठी",
|
20 |
-
"or": "Oriya - ଓଡ଼ିଆ",
|
21 |
-
"pa": "Panjabi - ਪੰਜਾਬੀ",
|
22 |
-
"raj": "Rajasthani - राजस्थानी",
|
23 |
-
"ta": "Tamil - தமிழ்",
|
24 |
-
"te": "Telugu - తెలుగు"
|
25 |
-
}
|
26 |
-
|
27 |
-
|
28 |
-
class Indic_TTS:
|
29 |
-
def __init__(self,lang,device):
|
30 |
-
model_id = "shethjenil/INDIC_TTS"
|
31 |
-
model_path = hf_hub_download(model_id, lang+"_fastpitch_best_model.pth")
|
32 |
-
vocoder_path = hf_hub_download(model_id, lang+"_hifigan_best_model.pth")
|
33 |
-
vocoder_config_path = hf_hub_download(model_id, lang+"_hifigan_config.json")
|
34 |
-
config_path = hf_hub_download(model_id, lang+"_fastpitch_config.json")
|
35 |
-
speaker_path = hf_hub_download(model_id, lang+"_fastpitch_speakers.pth")
|
36 |
-
conf = json_load(open(config_path))
|
37 |
-
conf['speakers_file'] = conf['model_args']['speakers_file'] = speaker_path
|
38 |
-
json_dump(conf, open(config_path, 'w'))
|
39 |
-
self.synthesizer = Synthesizer(model_path,config_path,vocoder_checkpoint=vocoder_path,vocoder_config=vocoder_config_path,use_cuda=device.type == "cuda")
|
40 |
-
self.speakers = self.synthesizer.tts_model.speaker_manager.speaker_names
|
41 |
-
def text2speech(self,text:str,speaker:str):
|
42 |
-
self.synthesizer.save_wav(self.synthesizer.tts(text,speaker),"output.wav")
|
43 |
-
"output.wav"
|
44 |
-
|
45 |
-
indic_tts_lang = getenv("indic_tts_lang")
|
46 |
-
tts_lang_name = lang_conf[indic_tts_lang]
|
47 |
-
tts_model = Indic_TTS(indic_tts_lang,Device("cuda" if cuda_is_available() else "cpu"))
|
48 |
-
|
49 |
-
import gradio as gr
|
50 |
-
gr.Interface(tts_model.text2speech,[gr.Textbox(label="Enter Text"),gr.Dropdown(tts_model.speakers, label="speaker"),],gr.Audio(type="filepath", label="Speech"),title=f"{tts_lang_name} TTS").launch()
|
|
|
1 |
+
from os import getenv
|
2 |
+
from huggingface_hub import hf_hub_download
|
3 |
+
from json import load as json_load , dump as json_dump
|
4 |
+
from torch import device as Device
|
5 |
+
from torch.cuda import is_available as cuda_is_available
|
6 |
+
from TTS.utils.synthesizer import Synthesizer
|
7 |
+
|
8 |
+
lang_conf = {
|
9 |
+
"as": "Assamese - অসমীয়া",
|
10 |
+
"bn": "Bangla - বাংলা",
|
11 |
+
"brx": "Boro - बड़ो",
|
12 |
+
"en": "English (Indian accent)",
|
13 |
+
"en+hi": "English+Hindi (Hinglish code-mixed)",
|
14 |
+
"gu": "Gujarati - ગુજરાતી",
|
15 |
+
"hi": "Hindi - हिंदी",
|
16 |
+
"kn": "Kannada - ಕನ್ನಡ",
|
17 |
+
"ml": "Malayalam - മലയാളം",
|
18 |
+
"mni": "Manipuri - মিতৈলোন",
|
19 |
+
"mr": "Marathi - मराठी",
|
20 |
+
"or": "Oriya - ଓଡ଼ିଆ",
|
21 |
+
"pa": "Panjabi - ਪੰਜਾਬੀ",
|
22 |
+
"raj": "Rajasthani - राजस्थानी",
|
23 |
+
"ta": "Tamil - தமிழ்",
|
24 |
+
"te": "Telugu - తెలుగు"
|
25 |
+
}
|
26 |
+
|
27 |
+
|
28 |
+
class Indic_TTS:
|
29 |
+
def __init__(self,lang,device):
|
30 |
+
model_id = "shethjenil/INDIC_TTS"
|
31 |
+
model_path = hf_hub_download(model_id, lang+"_fastpitch_best_model.pth")
|
32 |
+
vocoder_path = hf_hub_download(model_id, lang+"_hifigan_best_model.pth")
|
33 |
+
vocoder_config_path = hf_hub_download(model_id, lang+"_hifigan_config.json")
|
34 |
+
config_path = hf_hub_download(model_id, lang+"_fastpitch_config.json")
|
35 |
+
speaker_path = hf_hub_download(model_id, lang+"_fastpitch_speakers.pth")
|
36 |
+
conf = json_load(open(config_path))
|
37 |
+
conf['speakers_file'] = conf['model_args']['speakers_file'] = speaker_path
|
38 |
+
json_dump(conf, open(config_path, 'w'))
|
39 |
+
self.synthesizer = Synthesizer(model_path,config_path,vocoder_checkpoint=vocoder_path,vocoder_config=vocoder_config_path,use_cuda=device.type == "cuda")
|
40 |
+
self.speakers = self.synthesizer.tts_model.speaker_manager.speaker_names
|
41 |
+
def text2speech(self,text:str,speaker:str):
|
42 |
+
self.synthesizer.save_wav(self.synthesizer.tts(text,speaker),"output.wav")
|
43 |
+
return "output.wav"
|
44 |
+
|
45 |
+
indic_tts_lang = getenv("indic_tts_lang")
|
46 |
+
tts_lang_name = lang_conf[indic_tts_lang]
|
47 |
+
tts_model = Indic_TTS(indic_tts_lang,Device("cuda" if cuda_is_available() else "cpu"))
|
48 |
+
|
49 |
+
import gradio as gr
|
50 |
+
gr.Interface(tts_model.text2speech,[gr.Textbox(label="Enter Text"),gr.Dropdown(tts_model.speakers, label="speaker"),],gr.Audio(type="filepath", label="Speech"),title=f"{tts_lang_name} TTS").launch()
|