File size: 1,866 Bytes
f517129
 
 
 
 
 
 
 
 
 
 
 
1085965
f517129
 
 
 
 
 
 
 
 
 
1085965
 
 
 
 
f517129
 
 
 
 
 
 
 
 
 
1085965
fcd58cc
 
426d536
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import gradio as gr
import requests

API_URL = "https://api-inference.huggingface.co/models/facebook/mms-tts-eng"
HF_TOKEN = os.getenv("HF_TOKEN", "")
headers = {"Authorization": f"Bearer {HF_TOKEN}"} if HF_TOKEN else {}

def text_to_speech(text):
    if not text.strip():
        return None, "অনুগ্রহ করে কিছু টেক্সট লিখুন।"
    try:
        response = requests.post(API_URL, headers=headers, json={"inputs": text}, timeout=60)
        if response.status_code == 200:
            output_path = "voice.wav"
            with open(output_path, "wb") as f:
                f.write(response.content)
            return output_path, "ভয়েস সফলভাবে তৈরি হয়েছে!"
        else:
            return None, f"সার্ভার এরর কোড: {response.status_code}"
    except Exception as e:
        return None, f"নেটওয়ার্ক সমস্যা: {str(e)}"

# Gradio 6.0+ এর নিয়ম অনুযায়ী theme এখন launch() এ দিতে হয়
demo = gr.Blocks()

with demo:
    gr.Markdown("# 🎙️ Raybil Voice AI Engine")
    with gr.Row():
        with gr.Column():
            input_text = gr.Textbox(label="আপনার টেক্সট লিখুন", placeholder="এখানে ইংরেজি টেক্সট লিখুন...", lines=4)
            submit_btn = gr.Button("ভয়েস জেনারেট করুন", variant="primary")
        with gr.Column():
            output_audio = gr.Audio(label="জেনারেটেড ভয়েস", type="filepath")
            status_text = gr.Markdown()

    submit_btn.click(fn=text_to_speech, inputs=input_text, outputs=[output_audio, status_text])

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860)