Offex commited on
Commit
2d1af42
·
verified ·
1 Parent(s): 3a123cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -44
app.py CHANGED
@@ -1,45 +1,21 @@
1
- import os
2
  import gradio as gr
3
- from TTS.api import TTS
4
-
5
- # Coqui license agreement
6
- os.environ["COQUI_TOS_AGREED"] = "1"
7
-
8
- print("⏳ XTTS-v2 model load ho raha hai...")
9
- tts = TTS(
10
- model_name="tts_models/multilingual/multi-dataset/xtts_v2",
11
- gpu=False
12
- )
13
- print("✅ Model loaded")
14
-
15
- def generate_voice(text, audio_input, language):
16
- if audio_input is None:
17
- return None, "⚠️ Pehle apni awaaz upload / record karein"
18
-
19
- output_path = "output.wav"
20
- tts.tts_to_file(
21
- text=text,
22
- speaker_wav=audio_input,
23
- language=language,
24
- file_path=output_path
25
- )
26
- return output_path, "✅ Audio ready!"
27
-
28
- with gr.Blocks(title="Deepak AI Voice Studio") as demo:
29
- gr.Markdown("# 🎙️ Deepak AI Voice Studio")
30
- gr.Markdown("Apni awaaz se AI voice generate karein (XTTS-v2)")
31
-
32
- with gr.Row():
33
- with gr.Column():
34
- text = gr.Textbox(label="Text", lines=3)
35
- voice = gr.Audio(type="filepath", label="Voice sample (5–10 sec)")
36
- lang = gr.Dropdown(["hi", "en"], value="hi", label="Language")
37
- btn = gr.Button("Generate")
38
-
39
- with gr.Column():
40
- out = gr.Audio(label="Output")
41
- status = gr.Textbox(label="Status")
42
-
43
- btn.click(generate_voice, [text, voice, lang], [out, status])
44
-
45
- demo.launch()
 
 
1
  import gradio as gr
2
+ from transformers import BarkModel, AutoProcessor
3
+ import torch
4
+ import scipy.io.wavfile as wav
5
+
6
+ processor = AutoProcessor.from_pretrained("suno/bark")
7
+ model = BarkModel.from_pretrained("suno/bark")
8
+
9
+ def generate(text):
10
+ inputs = processor(text, return_tensors="pt")
11
+ audio = model.generate(**inputs)
12
+ audio = audio.cpu().numpy().squeeze()
13
+ wav.write("out.wav", 22050, audio)
14
+ return "out.wav"
15
+
16
+ gr.Interface(
17
+ fn=generate,
18
+ inputs=gr.Textbox(label="Text"),
19
+ outputs=gr.Audio(type="filepath"),
20
+ title="AI Voice Generator (HF Stable)"
21
+ ).launch()