Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from TTS.api import TTS
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# License Agreement Auto-Accept
|
| 6 |
+
os.environ["COQUI_TOS_AGREED"] = "1"
|
| 7 |
+
|
| 8 |
+
print("⏳ Model load ho raha hai...")
|
| 9 |
+
# GPU False rakha hai kyunki aap free tier par hain
|
| 10 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
|
| 11 |
+
print("✅ Model Ready!")
|
| 12 |
+
|
| 13 |
+
def get_voices():
|
| 14 |
+
if not os.path.exists("voices"):
|
| 15 |
+
os.makedirs("voices")
|
| 16 |
+
return []
|
| 17 |
+
return [f for f in os.listdir("voices") if f.endswith(".wav")]
|
| 18 |
+
|
| 19 |
+
def generate_voice(text, voice_name, language):
|
| 20 |
+
if not voice_name:
|
| 21 |
+
return None, "⚠️ Pehle koi voice select karein!"
|
| 22 |
+
|
| 23 |
+
speaker_path = os.path.join("voices", voice_name)
|
| 24 |
+
output_path = "output.wav"
|
| 25 |
+
|
| 26 |
+
tts.tts_to_file(text=text, file_path=output_path, speaker_wav=speaker_path, language=language)
|
| 27 |
+
return output_path, "✅ Audio Ban Gayi!"
|
| 28 |
+
|
| 29 |
+
with gr.Blocks(title="Deepak AI Voice") as demo:
|
| 30 |
+
gr.Markdown("# 🎙️ Clone Any Voice (11Labs Style)")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
with gr.Column():
|
| 34 |
+
txt = gr.Textbox(label="Text (Hindi/English)", value="Namaste Deepak, kaise ho aap?")
|
| 35 |
+
|
| 36 |
+
# Dropdown jo voices folder se list uthayega
|
| 37 |
+
voice_drop = gr.Dropdown(label="Select Character", choices=get_voices())
|
| 38 |
+
refresh_btn = gr.Button("🔄 List Refresh Karein")
|
| 39 |
+
|
| 40 |
+
lang = gr.Dropdown(label="Language", choices=["hi", "en"], value="hi")
|
| 41 |
+
btn = gr.Button("🔊 Generate Audio", variant="primary")
|
| 42 |
+
|
| 43 |
+
with gr.Column():
|
| 44 |
+
out_audio = gr.Audio(label="Output")
|
| 45 |
+
status = gr.Textbox(label="Status")
|
| 46 |
+
|
| 47 |
+
def refresh():
|
| 48 |
+
voices = get_voices()
|
| 49 |
+
return gr.Dropdown(choices=voices)
|
| 50 |
+
|
| 51 |
+
refresh_btn.click(refresh, outputs=voice_drop)
|
| 52 |
+
btn.click(generate_voice, inputs=[txt, voice_drop, lang], outputs=[out_audio, status])
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 56 |
+
|