Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,50 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
import tempfile
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
iface = gr.Interface(
|
| 20 |
-
fn=
|
| 21 |
inputs=[
|
| 22 |
gr.Textbox(lines=5, placeholder="हिंदी में टेक्स्ट दर्ज करें...", label="Text"),
|
| 23 |
-
gr.Audio(type="filepath", label="Voice Sample (
|
| 24 |
],
|
| 25 |
-
outputs=gr.Audio(type="filepath", label="Generated Speech"),
|
| 26 |
-
title="Hindi Text-to-Speech",
|
| 27 |
description=(
|
| 28 |
-
"Generate Hindi speech from text
|
| 29 |
-
"
|
| 30 |
)
|
| 31 |
)
|
| 32 |
|
| 33 |
iface.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from TTS.api import TTS
|
| 3 |
import tempfile
|
| 4 |
+
import librosa
|
| 5 |
+
import soundfile as sf
|
| 6 |
|
| 7 |
+
# Initialize Coqui TTS model for Hindi (IndicTTS)
|
| 8 |
+
tts_model_name = "tts_models/multilingual/multi-dataset/xtts_v2"
|
| 9 |
+
tts = TTS(tts_model_name)
|
| 10 |
+
|
| 11 |
+
def text_to_speech_clone(text, voice_sample):
|
| 12 |
+
if voice_sample is None:
|
| 13 |
+
return "Please provide a voice sample audio.", None
|
| 14 |
|
| 15 |
+
# Load voice sample
|
| 16 |
+
sample_wav, sample_rate = librosa.load(voice_sample, sr=22050)
|
| 17 |
+
|
| 18 |
+
# Save voice sample as wav temporarily
|
| 19 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_sample:
|
| 20 |
+
sf.write(tmp_sample.name, sample_wav, sample_rate)
|
| 21 |
+
voice_sample_path = tmp_sample.name
|
| 22 |
+
|
| 23 |
+
# Generate cloned speech in Hindi
|
| 24 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_output:
|
| 25 |
+
tts.tts_to_file(
|
| 26 |
+
text=text,
|
| 27 |
+
file_path=tmp_output.name,
|
| 28 |
+
speaker_wav=voice_sample_path,
|
| 29 |
+
language="hi"
|
| 30 |
+
)
|
| 31 |
+
output_path = tmp_output.name
|
| 32 |
+
|
| 33 |
+
return output_path
|
| 34 |
|
| 35 |
iface = gr.Interface(
|
| 36 |
+
fn=text_to_speech_clone,
|
| 37 |
inputs=[
|
| 38 |
gr.Textbox(lines=5, placeholder="हिंदी में टेक्स्ट दर्ज करें...", label="Text"),
|
| 39 |
+
gr.Audio(type="filepath", label="Voice Sample (Hindi speech)")
|
| 40 |
],
|
| 41 |
+
outputs=gr.Audio(type="filepath", label="Generated Cloned Speech"),
|
| 42 |
+
title="Hindi Text-to-Speech with Voice Cloning",
|
| 43 |
description=(
|
| 44 |
+
"Generate Hindi speech from text with voice cloning capability. "
|
| 45 |
+
"Provide a Hindi voice sample to clone its voice characteristics."
|
| 46 |
)
|
| 47 |
)
|
| 48 |
|
| 49 |
iface.launch()
|
| 50 |
+
|