SAD43W commited on
Commit
3c08b54
·
verified ·
1 Parent(s): 44c4441

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -37
app.py CHANGED
@@ -1,49 +1,24 @@
1
- import os
2
- os.environ["COQUI_TOS_AGREED"] = "1"
3
-
4
- import torch
5
- from torch.serialization import add_safe_globals
6
-
7
- from TTS.tts.configs.xtts_config import XttsConfig
8
- from TTS.tts.models.xtts import XttsAudioConfig
9
- from TTS.config.shared_configs import BaseDatasetConfig # NEW ADD
10
-
11
- add_safe_globals([XttsConfig, XttsAudioConfig, BaseDatasetConfig])
12
-
13
  from TTS.api import TTS
14
  import gradio as gr
 
 
 
 
15
 
16
- tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2")
17
  tts.to("cuda" if torch.cuda.is_available() else "cpu")
18
 
19
- def synthesize(text, speaker_wav):
20
  output_path = "output.wav"
21
- if speaker_wav is None:
22
- return "No voice sample uploaded.", None
23
-
24
- speaker_path = "temp_speaker.wav"
25
- speaker_wav.save(speaker_path)
26
-
27
- tts.tts_to_file(
28
- text=text,
29
- speaker_wav=speaker_path,
30
- language="en",
31
- file_path=output_path
32
- )
33
- return "Done. Listen below.", output_path
34
 
35
  iface = gr.Interface(
36
  fn=synthesize,
37
- inputs=[
38
- gr.Textbox(label="Text to Speak", placeholder="Come closer... I've been waiting in the dark."),
39
- gr.Audio(source="upload", type="file", label="Creepy Voice Sample")
40
- ],
41
- outputs=[
42
- gr.Textbox(label="Status"),
43
- gr.Audio(label="Result Audio")
44
- ],
45
- title="XTTS‑V2 Horror Whisperer 👻",
46
- description="Upload a voice and make it say creepy stuff. XTTS‑v2 powered, GPU-juiced. 🧟‍♂️💀"
47
  )
48
 
49
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from TTS.api import TTS
2
  import gradio as gr
3
+ import torch
4
+ import os
5
+
6
+ os.environ["CUDA_VISIBLE_DEVICES"] = "0" # Use GPU if available
7
 
8
+ tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC")
9
  tts.to("cuda" if torch.cuda.is_available() else "cpu")
10
 
11
+ def synthesize(text):
12
  output_path = "output.wav"
13
+ tts.tts_to_file(text=text, file_path=output_path)
14
+ return output_path
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  iface = gr.Interface(
17
  fn=synthesize,
18
+ inputs=gr.Textbox(lines=3, label="Enter text to synthesize"),
19
+ outputs=gr.Audio(type="filepath", label="Generated Speech"),
20
+ title="Mozilla Tacotron2 TTS - Smooth & Clean",
21
+ description="Simple text-to-speech using Mozilla's Tacotron2-DDC model. No voice samples required."
 
 
 
 
 
 
22
  )
23
 
24
  if __name__ == "__main__":