Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
7 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
8 |
|
9 |
-
# Load dataset
|
10 |
dataset = load_dataset("Emmylahot12/nnamdi", split="train")
|
|
|
11 |
|
12 |
-
#
|
13 |
-
if
|
14 |
raise ValueError("Dataset is empty or audio is missing")
|
15 |
|
16 |
-
#
|
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 |
-
#
|
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
|
38 |
-
gr.Dropdown(choices=["en", "fr", "es"
|
39 |
],
|
40 |
-
outputs=gr.Audio(label="Generated
|
41 |
-
title="Nnamdi TTS
|
42 |
-
|
|
|
|
|
|
|
|
|
|
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()
|