Namanrai commited on
Commit
2f667ed
·
verified ·
1 Parent(s): 5de9ce9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -32
app.py CHANGED
@@ -5,61 +5,49 @@ import noisereduce as nr
5
  import soundfile as sf
6
  import gc
7
 
8
- # Memory optimize kar rahe hain
9
  gc.collect()
10
  os.environ['COQUI_TOS_AGREED'] = '1'
11
 
12
- print("⏳ Loading Final Engine Strategy...")
13
 
14
- tts = None
15
- engine_status = ""
16
 
17
- # 🔄 AUTO-SWITCH LOGIC
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 voice_forge_api(text, reference_audio):
32
  if not text or not reference_audio:
33
- return None, "Script aur Voice dono daalo bhai!"
34
 
35
  try:
36
- # Audio cleaning
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
- output_path = "voice_output.wav"
43
 
44
- # Voice generation
45
- tts.tts_to_file(text=text, speaker_wav="clean_ref.wav", language="en", file_path=output_path)
46
 
47
- return output_path, f"Done! Powered by: {engine_status}"
48
  except Exception as e:
49
- return None, f"Error: {str(e)}"
50
 
51
- # Clean Professional UI
52
  iface = gr.Interface(
53
- fn=voice_forge_api,
54
  inputs=[
55
- gr.Textbox(label="Script", placeholder="Yahan apna text likho..."),
56
- gr.Audio(type="filepath", label="Voice Sample (Upload/Record)")
57
  ],
58
  outputs=[
59
- gr.Audio(label="Glowmation Voice Output"),
60
- gr.Textbox(label="Engine Info")
61
  ],
62
- title="🎙️ VoiceForge AI Studio"
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()