File size: 3,127 Bytes
3d25429
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Google Colab မှ ရရှိလာသော share URL ကို ဒီနေရာတွင် ထည့်ပါ
const COLAB_API_URL = "https://11dd2bd29abecbf287.gradio.live"; // <--- မိမိ Link ပြောင်းထည့်ပါ

document.getElementById('audioFile').addEventListener('change', function(e) {
    const fileName = e.target.files[0] ? e.target.files[0].name : '';
    document.getElementById('fileName').innerText = fileName ? `ရွေးချယ်ထားသော ဖိုင် - ${fileName}` : '';
});

document.getElementById('convertBtn').addEventListener('click', async function() {
    const fileInput = document.getElementById('audioFile');
    const statusDiv = document.getElementById('status');
    const audioPlayer = document.getElementById('audioPlayer');

    if (!fileInput.files || fileInput.files.length === 0) {
        statusDiv.innerText = 'ကျေးဇူးပြု၍ Audio ဖိုင်တစ်ခု အရင်ရွေးပေးပါ!';
        statusDiv.style.color = '#f87171';
        return;
    }

    const file = fileInput.files[0];
    statusDiv.style.color = '#38bdf8';
    statusDiv.innerText = 'AI မော်ဒယ်သို့ ပို့ဆောင်၍ အသံပြောင်းနေပါသည်။ ခဏစောင့်ပါ...';

    try {
        // Audio ဖိုင်ကို Base64/Form Data သို့ ပြောင်းလဲခြင်း
        const reader = new FileReader();
        reader.readAsDataURL(file);
        
        reader.onload = async function () {
            const base64Audio = reader.result;

            // Gradio API ထံ သို့ Request ပို့ခြင်း
            const response = await fetch(`${COLAB_API_URL}/api/predict/`, {
                method: "POST",
                headers: {
                    "Content-Type": "application/json"
                },
                body: JSON.stringify({
                    data: [base64Audio]
                })
            });

            const result = await response.json();

            if (result && result.data) {
                // ပြောင်းလဲပြီးသော Audio ရလဒ် ရယူခြင်း
                const outputAudioUrl = result.data[0];
                audioPlayer.src = outputAudioUrl;
                audioPlayer.style.display = 'block';
                statusDiv.innerText = 'ပြောင်းလဲမှု အောင်မြင်ပါသည်။ အောက်တွင် နားဆင်ပါ!';
                statusDiv.style.color = '#4ade80';
            } else {
                throw new Error("AI Server ၏ တုံ့ပြန်မှု မှားယွင်းနေပါသည်။");
            }
        };

    } catch (error) {
        console.error(error);
        statusDiv.innerText = 'အမှားတစ်ခု ဖြစ်ပေါ်ခဲ့ပါသည်။ Colab Server တက်နေမနေ စစ်ဆေးပေးပါ။';
        statusDiv.style.color = '#f87171';
    }
});