Emmylahot12 commited on
Commit
9412e46
·
verified ·
1 Parent(s): d569fd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -20
app.py CHANGED
@@ -1,26 +1,22 @@
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,16 +28,12 @@ def synthesize(text, language="en"):
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()
 
1
  import os
2
+ from datasets import load_dataset
3
  from TTS.api import TTS
 
4
  import gradio as gr
5
 
6
+ # Accept Coqui license automatically
7
  os.environ["COQUI_TOS_AGREED"] = "1"
8
 
9
+ # Load your dataset and retrieve the voice sample path
10
  dataset = load_dataset("Emmylahot12/nnamdi", split="train")
11
+ if dataset[0]["audio"] is None:
 
 
 
12
  raise ValueError("Dataset is empty or audio is missing")
13
 
 
14
  voice_sample_path = dataset[0]["audio"]["path"]
15
 
16
+ # Initialize the TTS engine (CPU)
17
  tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
18
 
19
+ # Inference function
20
  def synthesize(text, language="en"):
21
  output_path = "output.wav"
22
  tts.tts_to_file(
 
28
  return output_path
29
 
30
  # Gradio UI
31
+ gr.Interface(
32
  fn=synthesize,
33
  inputs=[
34
+ gr.Textbox(label="Enter text to synthesize"),
35
+ gr.Dropdown(["en", "fr", "es"], label="Language", value="en")
36
  ],
37
+ outputs=gr.Audio(label="Generated Audio"),
38
+ title="Nnamdi TTS App (XTTSv2)"
39
+ ).launch()