Namanrai commited on
Commit
5650de9
·
verified ·
1 Parent(s): f34ff9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -30
app.py CHANGED
@@ -1,56 +1,36 @@
1
  import os
2
- import torch
3
  import gradio as gr
4
  from TTS.api import TTS
5
  import noisereduce as nr
6
  import soundfile as sf
7
- import gc
8
 
9
- # Memory clear karne ke liye
10
- gc.collect()
11
-
12
- # Agreements
13
  os.environ['COQUI_TOS_AGREED'] = '1'
14
 
15
- print("⏳ Loading 1.5GB Engine (XTTS v1)... thoda wait kar!")
16
-
17
- tts = None
18
-
19
- try:
20
- # XTTS v1 load kar rahe hain (Size: ~1.5GB)
21
- tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts", gpu=False)
22
- print("✅ 1.5GB Engine Loaded!")
23
- except Exception as e:
24
- print(f"❌ Load Error: {str(e)}")
25
 
26
  def generate_api_voice(text, reference_audio):
27
- if tts is None:
28
- return None, "⚠️ Error: Server ki memory full ho gayi, engine load nahi hua."
29
-
30
  if not text or not reference_audio:
31
- return None, "⚠️ Error: Text aur Audio dono daal bhai!"
32
-
33
  try:
34
- # Voice processing
35
  data, rate = sf.read(reference_audio)
36
  if len(data.shape) > 1: data = data.mean(axis=1)
37
  clean_data = nr.reduce_noise(y=data, sr=rate)
38
  sf.write("clean_ref.wav", clean_data, rate)
39
-
40
  output_file = "output_voice.wav"
41
- # Language "en" (English) par best chalta hai v1
42
  tts.tts_to_file(text=text, speaker_wav="clean_ref.wav", language="en", file_path=output_file)
43
-
44
- return output_file, "✅ Voice Generated (v1)!"
45
  except Exception as e:
46
- return None, f"⚠️ Runtime Error: {str(e)}"
47
 
48
- # Interface
49
  iface = gr.Interface(
50
  fn=generate_api_voice,
51
  inputs=[gr.Textbox(label="Script"), gr.Audio(type="filepath", label="Reference")],
52
- outputs=[gr.Audio(label="Glowmation AI Result"), gr.Textbox(label="Status")],
53
- title="🎙️ Glowmation - 1.5GB Engine Test"
54
  )
55
 
56
  iface.launch()
 
1
  import os
 
2
  import gradio as gr
3
  from TTS.api import TTS
4
  import noisereduce as nr
5
  import soundfile as sf
 
6
 
 
 
 
 
7
  os.environ['COQUI_TOS_AGREED'] = '1'
8
 
9
+ print("⏳ Starting Safe Engine...")
10
+ # Ye halka engine hai, crash nahi hoga
11
+ tts = TTS("tts_models/multilingual/multi-dataset/your_tts")
12
+ print("✅ Engine Ready!")
 
 
 
 
 
 
13
 
14
  def generate_api_voice(text, reference_audio):
 
 
 
15
  if not text or not reference_audio:
16
+ return None, "Text and Audio required"
 
17
  try:
 
18
  data, rate = sf.read(reference_audio)
19
  if len(data.shape) > 1: data = data.mean(axis=1)
20
  clean_data = nr.reduce_noise(y=data, sr=rate)
21
  sf.write("clean_ref.wav", clean_data, rate)
22
+
23
  output_file = "output_voice.wav"
 
24
  tts.tts_to_file(text=text, speaker_wav="clean_ref.wav", language="en", file_path=output_file)
25
+ return output_file, "Success"
 
26
  except Exception as e:
27
+ return None, str(e)
28
 
29
+ # Ekdum clean UI, bina kisi extra technical pins ya clutter ke
30
  iface = gr.Interface(
31
  fn=generate_api_voice,
32
  inputs=[gr.Textbox(label="Script"), gr.Audio(type="filepath", label="Reference")],
33
+ outputs=[gr.Audio(label="VoiceForge Output"), gr.Textbox(label="Status")]
 
34
  )
35
 
36
  iface.launch()