Spaces:
Runtime error
Runtime error
eaysu
commited on
Commit
·
1445567
1
Parent(s):
94306c5
initial commit
Browse files- .DS_Store +0 -0
- app.py +59 -0
- requirements.txt +4 -0
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from TTS.api import TTS
|
3 |
+
import gradio as gr
|
4 |
+
import soundfile as sf
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
# Get device
|
8 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
+
|
10 |
+
# Initialize TTS model
|
11 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
12 |
+
|
13 |
+
# Define available languages
|
14 |
+
AVAILABLE_LANGUAGES = ["en", "de", "fr", "it", "es", "tr"]
|
15 |
+
|
16 |
+
# Function to generate cloned voice
|
17 |
+
def clone_voice(text, language, speaker_wav):
|
18 |
+
# Ensure the language is supported
|
19 |
+
if language not in AVAILABLE_LANGUAGES:
|
20 |
+
raise ValueError(f"Language '{language}' is not supported. Available languages: {AVAILABLE_LANGUAGES}")
|
21 |
+
|
22 |
+
# Generate speech
|
23 |
+
wav = tts.tts(text=text, speaker_wav=speaker_wav, language=language)
|
24 |
+
|
25 |
+
# Save the output to a temporary file
|
26 |
+
output_file = "output.wav"
|
27 |
+
sf.write(output_file, wav, 22050)
|
28 |
+
|
29 |
+
return output_file
|
30 |
+
|
31 |
+
# Gradio interface
|
32 |
+
def gradio_interface(text, language, speaker_wav):
|
33 |
+
try:
|
34 |
+
output_file = clone_voice(text, language, speaker_wav)
|
35 |
+
return output_file
|
36 |
+
except Exception as e:
|
37 |
+
return str(e)
|
38 |
+
|
39 |
+
# Define Gradio inputs and outputs
|
40 |
+
inputs = [
|
41 |
+
gr.Textbox(label="Text to speak", placeholder="Enter text here..."),
|
42 |
+
gr.Dropdown(label="Language", choices=AVAILABLE_LANGUAGES, value="en"),
|
43 |
+
gr.Audio(label="Reference Voice (Upload or Record)", type="filepath"),
|
44 |
+
]
|
45 |
+
|
46 |
+
outputs = gr.Audio(label="Cloned Voice Output")
|
47 |
+
|
48 |
+
# Create Gradio interface
|
49 |
+
interface = gr.Interface(
|
50 |
+
fn=gradio_interface,
|
51 |
+
inputs=inputs,
|
52 |
+
outputs=outputs,
|
53 |
+
title="Voice Cloning with Coqui TTS",
|
54 |
+
description="Upload or record a reference voice, enter text, and select a language to generate a cloned voice.",
|
55 |
+
live=False,
|
56 |
+
)
|
57 |
+
|
58 |
+
# Launch the interface
|
59 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
TTS
|
3 |
+
gradio
|
4 |
+
soundfile
|