Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from TTS.api import TTS
|
| 3 |
import tempfile
|
| 4 |
import librosa
|
| 5 |
import soundfile as sf
|
| 6 |
|
| 7 |
-
#
|
|
|
|
|
|
|
|
|
|
| 8 |
tts_model_name = "tts_models/multilingual/multi-dataset/xtts_v2"
|
| 9 |
tts = TTS(tts_model_name)
|
| 10 |
|
|
@@ -12,15 +16,15 @@ 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
|
| 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
|
| 24 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_output:
|
| 25 |
tts.tts_to_file(
|
| 26 |
text=text,
|
|
@@ -47,4 +51,3 @@ iface = gr.Interface(
|
|
| 47 |
)
|
| 48 |
|
| 49 |
iface.launch()
|
| 50 |
-
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
from TTS.api import TTS
|
| 4 |
import tempfile
|
| 5 |
import librosa
|
| 6 |
import soundfile as sf
|
| 7 |
|
| 8 |
+
# Explicitly accept TTS terms of service
|
| 9 |
+
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 10 |
+
|
| 11 |
+
# Load Coqui TTS XTTS model
|
| 12 |
tts_model_name = "tts_models/multilingual/multi-dataset/xtts_v2"
|
| 13 |
tts = TTS(tts_model_name)
|
| 14 |
|
|
|
|
| 16 |
if voice_sample is None:
|
| 17 |
return "Please provide a voice sample audio.", None
|
| 18 |
|
| 19 |
+
# Load voice sample audio
|
| 20 |
sample_wav, sample_rate = librosa.load(voice_sample, sr=22050)
|
| 21 |
|
| 22 |
+
# Save sample temporarily in correct format
|
| 23 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_sample:
|
| 24 |
sf.write(tmp_sample.name, sample_wav, sample_rate)
|
| 25 |
voice_sample_path = tmp_sample.name
|
| 26 |
|
| 27 |
+
# Generate cloned Hindi speech
|
| 28 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_output:
|
| 29 |
tts.tts_to_file(
|
| 30 |
text=text,
|
|
|
|
| 51 |
)
|
| 52 |
|
| 53 |
iface.launch()
|
|
|