Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
7 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
8 |
|
9 |
-
# Load dataset
|
10 |
dataset = load_dataset("Emmylahot12/nnamdi", split="train")
|
11 |
-
|
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
|
21 |
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
|
22 |
|
23 |
-
#
|
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 |
-
|
36 |
fn=synthesize,
|
37 |
inputs=[
|
38 |
-
gr.Textbox(label="Enter
|
39 |
-
gr.Dropdown(
|
40 |
],
|
41 |
-
outputs=gr.Audio(label="Generated
|
42 |
-
title="Nnamdi TTS
|
43 |
-
|
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()
|
|
|
|
|
|
|
|