Namanrai commited on
Commit
8f12b2f
·
verified ·
1 Parent(s): ede3d9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -29
app.py CHANGED
@@ -1,49 +1,47 @@
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
  import gc
7
 
8
- # Memory clear karo taaki server hamesha zinda rahe
9
  gc.collect()
10
- os.environ['COQUI_TOS_AGREED'] = '1'
11
 
12
- print("⏳ Loading VoiceForge Cloning Engine...")
13
- # Sabse stable cloning engine jo HF free tier par nahi rukta
14
- tts = TTS("tts_models/multilingual/multi-dataset/your_tts")
15
- print("✅ Engine Ready & Running!")
16
 
17
- def generate_api_voice(text, reference_audio):
18
- if not text or not reference_audio:
19
- return None, "Error: Script aur Reference Voice dono zaroori hain!"
20
 
21
- try:
22
- # Background noise saaf karne ka automatic system
23
- data, rate = sf.read(reference_audio)
24
- if len(data.shape) > 1: data = data.mean(axis=1)
25
- clean_data = nr.reduce_noise(y=data, sr=rate)
26
- sf.write("clean_ref.wav", clean_data, rate)
27
 
 
 
 
 
 
 
 
 
28
  output_file = "output_voice.wav"
29
- tts.tts_to_file(text=text, speaker_wav="clean_ref.wav", language="en", file_path=output_file)
30
 
31
  return output_file, "✅ API Status: Success"
32
  except Exception as e:
33
  return None, f"⚠️ Engine Error: {str(e)}"
34
 
35
- # Ekdum clean UI (Bina kisi extra pins ya technical labels ke)
36
  iface = gr.Interface(
37
  fn=generate_api_voice,
38
- inputs=[
39
- gr.Textbox(label="Apni Script Yahan Likho"),
40
- gr.Audio(type="filepath", label="Reference Voice Upload")
41
- ],
42
- outputs=[
43
- gr.Audio(label="VoiceForge Output"),
44
- gr.Textbox(label="Status")
45
- ],
46
- title="🎙️ VoiceForge AI Studio"
47
  )
48
 
49
  iface.launch()
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
3
  import soundfile as sf
4
+ import torch
5
+ from datasets import load_dataset
6
  import gc
7
 
8
+ # System ki purani memory saaf karna
9
  gc.collect()
 
10
 
11
+ print("⏳ WARNING: Loading the BIGGEST Engine... Server crash hone ke chances hain!")
 
 
 
12
 
13
+ try:
14
+ # Heavy Text-to-Speech pipeline load kar rahe hain
15
+ synthesizer = pipeline("text-to-speech", "microsoft/speecht5_tts")
16
 
17
+ # High-quality speaker embedding
18
+ embeddings_dataset = load_dataset("Matthijs/cmu_arctic_xvectors", split="validation")
19
+ speaker_embedding = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
20
+ print("✅ Engine load ho gaya! (Ye ek miracle hai)")
21
+ except Exception as e:
22
+ print(f" Server Crashed: {e}")
23
 
24
+ def generate_api_voice(text):
25
+ if not text:
26
+ return None, "Error: Script likhna zaruri hai!"
27
+
28
+ try:
29
+ # Aawaz generate karne ka heavy process
30
+ speech = synthesizer(text, forward_params={"speaker_embeddings": speaker_embedding})
31
+
32
  output_file = "output_voice.wav"
33
+ sf.write(output_file, speech["audio"], samplerate=speech["sampling_rate"])
34
 
35
  return output_file, "✅ API Status: Success"
36
  except Exception as e:
37
  return None, f"⚠️ Engine Error: {str(e)}"
38
 
39
+ # Ekdum clean UI (No extra clutter)
40
  iface = gr.Interface(
41
  fn=generate_api_voice,
42
+ inputs=[gr.Textbox(label="Apni Script Yahan Likho")],
43
+ outputs=[gr.Audio(label="VoiceForge Output"), gr.Textbox(label="Status")],
44
+ title="🎙️ VoiceForge AI Studio - Heavy Engine Test"
 
 
 
 
 
 
45
  )
46
 
47
  iface.launch()