File size: 3,158 Bytes
6db5c41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>منصة لَـهْجة - توليد الصوت</title>
    <link rel="stylesheet" href="style.css">
    <link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@400;700&display=swap" rel="stylesheet">
</head>
<body>
    <div class="container">
        <header>
            <h1>منصة لَـهْجة</h1>
            <p>توليد الصوت باللهجة النجدية</p>
        </header>

        <div class="voice-box">
            <textarea id="textInput" placeholder="اكتب النص الذي تريد تحويله إلى صوت..."></textarea>
            <div class="controls">
                <select id="voiceSelect">
                    <option value="alloy">صوت رجالي</option>
                    <option value="echo">صوت نسائي</option>
                </select>
                <button id="generateBtn">توليد الصوت</button>
            </div>
            <div class="audio-container" id="audioContainer" style="display: none;">
                <audio id="audioPlayer" controls></audio>
                <a id="downloadLink" class="btn">تحميل الصوت</a>
            </div>
        </div>
    </div>

    <script>
        document.getElementById('generateBtn').addEventListener('click', async function() {
            const text = document.getElementById('textInput').value;
            const voice = document.getElementById('voiceSelect').value;
            
            if (!text) {
                alert('الرجاء إدخال نص');
                return;
            }

            try {
                const response = await fetch('/generate-voice', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        text: text,
                        voice: voice
                    })
                });

                if (response.ok) {
                    const blob = await response.blob();
                    const audioUrl = URL.createObjectURL(blob);
                    
                    const audioPlayer = document.getElementById('audioPlayer');
                    const audioContainer = document.getElementById('audioContainer');
                    const downloadLink = document.getElementById('downloadLink');
                    
                    audioPlayer.src = audioUrl;
                    audioContainer.style.display = 'block';
                    downloadLink.href = audioUrl;
                    downloadLink.download = 'lahja-voice.wav';
                    
                    audioPlayer.play();
                } else {
                    alert('حدث خطأ أثناء توليد الصوت');
                }
            } catch (error) {
                console.error('Error:', error);
                alert('حدث خطأ أثناء الاتصال بالخادم');
            }
        });
    </script>
</body>
</html>