Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,61 +5,49 @@ import noisereduce as nr
|
|
| 5 |
import soundfile as sf
|
| 6 |
import gc
|
| 7 |
|
| 8 |
-
# Memory optimize
|
| 9 |
gc.collect()
|
| 10 |
os.environ['COQUI_TOS_AGREED'] = '1'
|
| 11 |
|
| 12 |
-
print("⏳
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
try:
|
| 19 |
-
# Level 1: NeuTTS (XTTS v2) - Best Quality
|
| 20 |
-
print("🚀 Attempting to load NeuTTS Air...")
|
| 21 |
-
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
|
| 22 |
-
engine_status = "NeuTTS (Pro Quality)"
|
| 23 |
-
print("✅ NeuTTS Loaded Successfully!")
|
| 24 |
-
except Exception as e:
|
| 25 |
-
# Level 2: Your_TTS - Guaranteed Stability
|
| 26 |
-
print(f"⚠️ RAM Limit Hit! Switching to Your_TTS. Error: {e}")
|
| 27 |
-
tts = TTS("tts_models/multilingual/multi-dataset/your_tts")
|
| 28 |
-
engine_status = "Stable Your_TTS (Standard)"
|
| 29 |
-
print("✅ Backup Engine Loaded!")
|
| 30 |
|
| 31 |
-
def
|
| 32 |
if not text or not reference_audio:
|
| 33 |
-
return None, "Script
|
| 34 |
|
| 35 |
try:
|
| 36 |
-
# Audio
|
| 37 |
data, rate = sf.read(reference_audio)
|
| 38 |
if len(data.shape) > 1: data = data.mean(axis=1)
|
| 39 |
clean_data = nr.reduce_noise(y=data, sr=rate)
|
| 40 |
sf.write("clean_ref.wav", clean_data, rate)
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
-
# Voice
|
| 45 |
-
tts.tts_to_file(text=text, speaker_wav="clean_ref.wav", language="en", file_path=
|
| 46 |
|
| 47 |
-
return
|
| 48 |
except Exception as e:
|
| 49 |
-
return None, f"Error: {str(e)}"
|
| 50 |
|
| 51 |
-
#
|
| 52 |
iface = gr.Interface(
|
| 53 |
-
fn=
|
| 54 |
inputs=[
|
| 55 |
-
gr.Textbox(label="Script"
|
| 56 |
-
gr.Audio(type="filepath", label="Voice
|
| 57 |
],
|
| 58 |
outputs=[
|
| 59 |
-
gr.Audio(label="
|
| 60 |
-
gr.Textbox(label="
|
| 61 |
],
|
| 62 |
-
title="🎙️ VoiceForge AI
|
| 63 |
)
|
| 64 |
|
| 65 |
iface.launch()
|
|
|
|
| 5 |
import soundfile as sf
|
| 6 |
import gc
|
| 7 |
|
| 8 |
+
# Memory optimize
|
| 9 |
gc.collect()
|
| 10 |
os.environ['COQUI_TOS_AGREED'] = '1'
|
| 11 |
|
| 12 |
+
print("⏳ Starting Bulletproof Backend (Stable Mode)...")
|
| 13 |
|
| 14 |
+
# Bina kisi auto-switch ke, seedha sabse stable engine load kar rahe hain
|
| 15 |
+
tts = TTS("tts_models/multilingual/multi-dataset/your_tts")
|
| 16 |
|
| 17 |
+
print("✅ System 100% Stable and Running!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
def generate_api_voice(text, reference_audio):
|
| 20 |
if not text or not reference_audio:
|
| 21 |
+
return None, "Error: Script ya Voice missing hai bhai!"
|
| 22 |
|
| 23 |
try:
|
| 24 |
+
# Audio se shor (noise) hatana
|
| 25 |
data, rate = sf.read(reference_audio)
|
| 26 |
if len(data.shape) > 1: data = data.mean(axis=1)
|
| 27 |
clean_data = nr.reduce_noise(y=data, sr=rate)
|
| 28 |
sf.write("clean_ref.wav", clean_data, rate)
|
| 29 |
|
| 30 |
+
output_file = "output_voice.wav"
|
| 31 |
|
| 32 |
+
# Voice generate karna
|
| 33 |
+
tts.tts_to_file(text=text, speaker_wav="clean_ref.wav", language="en", file_path=output_file)
|
| 34 |
|
| 35 |
+
return output_file, "✅ Success: API is Live!"
|
| 36 |
except Exception as e:
|
| 37 |
+
return None, f"⚠️ Engine Error: {str(e)}"
|
| 38 |
|
| 39 |
+
# Ekdum saaf UI (No extra clutter)
|
| 40 |
iface = gr.Interface(
|
| 41 |
+
fn=generate_api_voice,
|
| 42 |
inputs=[
|
| 43 |
+
gr.Textbox(label="Script"),
|
| 44 |
+
gr.Audio(type="filepath", label="Voice Upload")
|
| 45 |
],
|
| 46 |
outputs=[
|
| 47 |
+
gr.Audio(label="Voice Output"),
|
| 48 |
+
gr.Textbox(label="API Status")
|
| 49 |
],
|
| 50 |
+
title="🎙️ VoiceForge AI - Stable Backend"
|
| 51 |
)
|
| 52 |
|
| 53 |
iface.launch()
|