Offex commited on
Commit
1baa152
·
verified ·
1 Parent(s): c621882

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -35
app.py CHANGED
@@ -1,44 +1,51 @@
1
  import gradio as gr
2
- import os
3
- from openvoice import se_extractor
4
- from openvoice.api import ToneColorConverter
 
5
 
6
- # मॉडल और कॉन्फ़िगरेशन लोड करना
7
- ckpt_converter = 'checkpoints_v2/converter'
8
  device = "cpu"
9
- tone_color_converter = ToneColorConverter(f'{ckpt_converter}/config.json', device=device)
10
- tone_color_converter.load_ckpt(f'{ckpt_converter}/checkpoint.pth')
11
 
12
- def clone_alex_voice(text, reference_audio):
13
- if reference_audio is None:
14
- return "कृपया Alex का सैंपल अपलोड करें!"
15
-
16
- # Alex की आवाज़ से 'Tone' निकालना
17
- target_se, audio_name = se_extractor.get_se(reference_audio, tone_color_converter, target_dir='processed', vad=True)
18
-
19
- # आवाज़ जनरेट करना (यहाँ हम बेस के लिए एक साफ़ आवाज़ यूज़ करेंगे)
20
- output_path = "alex_clone.wav"
21
-
22
- # क्लॉनिंग और टोन मैचिंग
23
- tone_color_converter.convert(
24
- model_src='base_model',
25
- src_se=source_se,
26
- tgt_se=target_se,
27
- output_path=output_path,
28
- message=text
29
- )
30
- return output_path
 
 
31
 
32
- # UI
33
- with gr.Blocks() as demo:
34
- gr.Markdown("# 🎙️ Alex Expressive Cloner (No-API Version)")
35
- with gr.Row():
36
- txt = gr.Textbox(label="Text to Speak")
37
- ref = gr.Audio(label="Upload Alex Voice Sample (10 sec)", type="filepath")
38
 
39
- btn = gr.Button("Clone Now")
40
- out = gr.Audio(label="Result")
 
 
 
 
41
 
42
- btn.click(clone_alex_voice, inputs=[txt, ref], outputs=out)
 
 
 
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()