Emmylahot12 commited on
Commit
251e1c4
·
verified ·
1 Parent(s): 9779fcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -1,25 +1,26 @@
1
  import os
2
- from datasets import load_dataset
3
  from TTS.api import TTS
 
4
  import gradio as gr
5
 
6
- # Auto-accept Coqui license
7
  os.environ["COQUI_TOS_AGREED"] = "1"
8
 
9
- # Load dataset
10
  dataset = load_dataset("Emmylahot12/nnamdi", split="train")
 
11
 
12
- # Check if dataset is valid
13
- if dataset is None or len(dataset) == 0 or "audio" not in dataset[0] or dataset[0]["audio"] is None:
14
  raise ValueError("Dataset is empty or audio is missing")
15
 
16
- # Get reference audio path
17
  voice_sample_path = dataset[0]["audio"]["path"]
18
 
19
- # Initialize TTS
20
- tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
21
 
22
- # Synthesize speech
23
  def synthesize(text, language="en"):
24
  output_path = "output.wav"
25
  tts.tts_to_file(
@@ -31,12 +32,16 @@ def synthesize(text, language="en"):
31
  return output_path
32
 
33
  # Gradio UI
34
- gr.Interface(
35
  fn=synthesize,
36
  inputs=[
37
- gr.Textbox(label="Enter text"),
38
- gr.Dropdown(choices=["en", "fr", "es"], label="Language", value="en")
39
  ],
40
- outputs=gr.Audio(label="Generated Audio"),
41
- title="Nnamdi TTS App"
42
- ).launch()
 
 
 
 
 
1
  import os
 
2
  from TTS.api import TTS
3
+ from datasets import load_dataset, Audio
4
  import gradio as gr
5
 
6
+ # Automatically accept Coqui license
7
  os.environ["COQUI_TOS_AGREED"] = "1"
8
 
9
+ # Load dataset from Hugging Face
10
  dataset = load_dataset("Emmylahot12/nnamdi", split="train")
11
+ dataset = dataset.cast_column("audio", Audio())
12
 
13
+ # Validate audio exists
14
+ if not dataset or not dataset[0]["audio"] or not dataset[0]["audio"]["path"]:
15
  raise ValueError("Dataset is empty or audio is missing")
16
 
17
+ # Reference voice sample path
18
  voice_sample_path = dataset[0]["audio"]["path"]
19
 
20
+ # Initialize TTS with XTTS v2 model (CPU mode)
21
+ tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
22
 
23
+ # TTS synthesis function
24
  def synthesize(text, language="en"):
25
  output_path = "output.wav"
26
  tts.tts_to_file(
 
32
  return output_path
33
 
34
  # Gradio UI
35
+ interface = gr.Interface(
36
  fn=synthesize,
37
  inputs=[
38
+ gr.Textbox(label="Enter Text"),
39
+ gr.Dropdown(choices=["en", "fr", "es", "de"], label="Language")
40
  ],
41
+ outputs=gr.Audio(label="Generated Speech"),
42
+ title="Nnamdi TTS - Powered by Coqui XTTS v2",
43
+ description="Custom voice from dataset: Emmylahot12/nnamdi"
44
+ )
45
+
46
+ if __name__ == "__main__":
47
+ interface.launch()