Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,51 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
# मॉडल
|
| 7 |
-
ckpt_converter = 'checkpoints_v2/converter'
|
| 8 |
device = "cpu"
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
with gr.Blocks() as demo:
|
| 34 |
-
gr.Markdown("# 🎙️ Alex Expressive
|
| 35 |
-
|
| 36 |
-
txt = gr.Textbox(label="Text to Speak")
|
| 37 |
-
ref = gr.Audio(label="Upload Alex Voice Sample (10 sec)", type="filepath")
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import BarkModel, BarkProcessor
|
| 3 |
+
import torch
|
| 4 |
+
import scipy.io.wavfile as wavfile
|
| 5 |
+
import numpy as np
|
| 6 |
|
| 7 |
+
# मॉडल लोड करना (यह Hugging Face का अपना मॉडल है, इसलिए एरर नहीं आएगा)
|
|
|
|
| 8 |
device = "cpu"
|
| 9 |
+
processor = BarkProcessor.from_pretrained("suno/bark-small")
|
| 10 |
+
model = BarkModel.from_pretrained("suno/bark-small").to(device)
|
| 11 |
|
| 12 |
+
def generate_alex_voice(text):
|
| 13 |
+
try:
|
| 14 |
+
# Alex जैसी 'Expressive' फील देने के लिए प्रॉम्प्ट का इस्तेमाल
|
| 15 |
+
# [laughter], [hesitation], [sigh] जैसे टैग्स यहाँ काम करते हैं
|
| 16 |
+
inputs = processor(text, voice_preset="v2/en_speaker_6") # Speaker 6 Alex जैसा मेल वॉइस है
|
| 17 |
+
|
| 18 |
+
# आवाज़ जनरेट करना
|
| 19 |
+
with torch.no_grad():
|
| 20 |
+
audio_array = model.generate(**inputs)
|
| 21 |
+
|
| 22 |
+
# ऑडियो को numpy array में बदलना
|
| 23 |
+
audio_array = audio_array.cpu().numpy().squeeze()
|
| 24 |
+
|
| 25 |
+
# फाइल सेव करना
|
| 26 |
+
sample_rate = model.generation_config.sample_rate
|
| 27 |
+
output_file = "alex_expressive_output.wav"
|
| 28 |
+
wavfile.write(output_file, sample_rate, audio_array)
|
| 29 |
+
|
| 30 |
+
return output_file
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return f"Error: {str(e)}"
|
| 33 |
|
| 34 |
+
# इंटरफेस डिज़ाइन (Deepak के लिए सरल और साफ़)
|
| 35 |
+
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
| 36 |
+
gr.Markdown("# 🎙️ Alex-Style Expressive TTS")
|
| 37 |
+
gr.Markdown("ElevenLabs Alex की तरह इमोशन्स के साथ आवाज़ बनाएँ।")
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
with gr.Row():
|
| 40 |
+
input_txt = gr.Textbox(
|
| 41 |
+
label="अपना टेक्स्ट लिखें (Expression के लिए [laughter] या [sigh] जोड़ें)",
|
| 42 |
+
placeholder="Hello! [laughter] How are you doing today?",
|
| 43 |
+
lines=3
|
| 44 |
+
)
|
| 45 |
|
| 46 |
+
submit_btn = gr.Button("Generate Voice", variant="primary")
|
| 47 |
+
audio_out = gr.Audio(label="Output Audio")
|
| 48 |
+
|
| 49 |
+
submit_btn.click(generate_alex_voice, inputs=input_txt, outputs=audio_out)
|
| 50 |
|
| 51 |
demo.launch()
|