File size: 6,869 Bytes
3f5d3d8
 
 
 
 
f25fc28
3f5d3d8
 
 
27fbe7f
 
3f5d3d8
27fbe7f
 
 
 
3f5d3d8
27fbe7f
 
3f5d3d8
 
27fbe7f
 
3f5d3d8
27fbe7f
3f5d3d8
 
27fbe7f
20709bb
3f5d3d8
27fbe7f
3f5d3d8
27fbe7f
 
 
20709bb
27fbe7f
20709bb
27fbe7f
 
 
 
3f5d3d8
f25fc28
 
 
 
 
 
 
 
 
 
 
 
 
 
3f5d3d8
 
 
27fbe7f
 
 
 
f25fc28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27fbe7f
 
 
 
 
 
 
 
3f5d3d8
 
 
 
 
27fbe7f
 
 
 
f25fc28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27fbe7f
 
 
f25fc28
27fbe7f
 
 
 
 
 
 
3f5d3d8
27fbe7f
3f5d3d8
 
 
27fbe7f
3f5d3d8
 
 
27fbe7f
3f5d3d8
27fbe7f
 
3f5d3d8
27fbe7f
 
f25fc28
 
 
 
 
 
 
 
 
27fbe7f
 
 
20709bb
 
 
27fbe7f
 
 
3f5d3d8
 
27fbe7f
 
 
 
 
 
3f5d3d8
20709bb
27fbe7f
 
 
 
 
20709bb
27fbe7f
 
 
 
3f5d3d8
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html dir="rtl" lang="ar">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>محادثة صوتية مصرية</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background: #f0f2f5;
        }
        .container {
            max-width: 600px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        button {
            background: #0084ff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            margin: 5px;
        }
        button:disabled {
            background: #ccc;
        }
        #transcription, #response {
            margin: 20px 0;
            padding: 15px;
            border-radius: 5px;
            background: #f8f9fa;
        }
        .label {
            font-weight: bold;
            color: #666;
            margin-bottom: 5px;
        }
        .voice-controls {
            margin: 15px 0;
            padding: 10px;
            background: #f8f9fa;
            border-radius: 5px;
        }
        .voice-controls label {
            display: block;
            margin: 5px 0;
        }
        select, input {
            margin: 5px;
            padding: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <button id="startBtn">ابدأ التحدث</button>
        <button id="stopBtn" disabled>توقف</button>
        
        <div class="voice-controls">
            <label>
                الصوت:
                <select id="voiceSelect"></select>
            </label>
            <label>
                سرعة الكلام:
                <input type="range" id="rateRange" min="0.5" max="2" step="0.1" value="1">
                <span id="rateValue">1</span>
            </label>
            <label>
                درجة الصوت:
                <input type="range" id="pitchRange" min="0.5" max="2" step="0.1" value="1">
                <span id="pitchValue">1</span>
            </label>
        </div>
        
        <div id="transcription">
            <div class="label">ما قلته:</div>
            <div id="spokenText"></div>
        </div>
        
        <div id="response">
            <div class="label">رد النموذج:</div>
            <div id="modelResponse"></div>
        </div>
    </div>

    <script>
        const API_URL = 'https://8o1mzdgh9f40t4-7777.proxy.runpod.net/proxy/8000/chat';
        const startBtn = document.getElementById('startBtn');
        const stopBtn = document.getElementById('stopBtn');
        const spokenText = document.getElementById('spokenText');
        const modelResponse = document.getElementById('modelResponse');
        const voiceSelect = document.getElementById('voiceSelect');
        const rateRange = document.getElementById('rateRange');
        const pitchRange = document.getElementById('pitchRange');
        const rateValue = document.getElementById('rateValue');
        const pitchValue = document.getElementById('pitchValue');
        
        // تحديث قائمة الأصوات المتاحة
        function populateVoiceList() {
            const voices = speechSynthesis.getVoices();
            voiceSelect.innerHTML = '';
            
            voices.forEach((voice, index) => {
                if (voice.lang.includes('ar')) {  // فقط الأصوات العربية
                    const option = document.createElement('option');
                    option.textContent = `${voice.name} (${voice.lang})`;
                    option.setAttribute('data-voice-index', index);
                    voiceSelect.appendChild(option);
                }
            });
        }

        speechSynthesis.onvoiceschanged = populateVoiceList;
        populateVoiceList();

        // تحديث قيم السرعة والنبرة
        rateRange.onchange = () => rateValue.textContent = rateRange.value;
        pitchRange.onchange = () => pitchValue.textContent = pitchRange.value;
        
        // إعداد التعرف على الكلام
        const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
        recognition.lang = 'ar-EG';  // تعيين اللغة للهجة المصرية
        recognition.continuous = false;
        recognition.interimResults = false;

        recognition.onresult = async (event) => {
            const text = event.results[0][0].transcript;
            spokenText.textContent = text;
            
            try {
                // إرسال النص إلى النموذج
                const response = await fetch(API_URL, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ message: text })
                });

                const data = await response.json();
                const botReply = data.response;
                modelResponse.textContent = botReply;

                // تحويل الرد إلى صوت
                const utterance = new SpeechSynthesisUtterance(botReply);
                
                // تعيين خصائص الصوت
                const voices = speechSynthesis.getVoices();
                const selectedVoice = voices[voiceSelect.selectedOptions[0].getAttribute('data-voice-index')];
                utterance.voice = selectedVoice;
                utterance.rate = parseFloat(rateRange.value);
                utterance.pitch = parseFloat(pitchRange.value);
                utterance.lang = 'ar-EG';  // تعيين اللغة للهجة المصرية
                
                speechSynthesis.speak(utterance);
            } catch (error) {
                modelResponse.textContent = 'حدث خطأ في الاتصال بالنموذج';
            }
        };

        recognition.onerror = (event) => {
            console.error('خطأ:', event.error);
            spokenText.textContent = 'حدث خطأ في التعرف على الكلام';
        };

        startBtn.onclick = () => {
            recognition.start();
            startBtn.disabled = true;
            stopBtn.disabled = false;
            spokenText.textContent = '';
            modelResponse.textContent = '';
        };

        stopBtn.onclick = () => {
            recognition.stop();
            startBtn.disabled = false;
            stopBtn.disabled = true;
        };

        recognition.onend = () => {
            startBtn.disabled = false;
            stopBtn.disabled = true;
        };
    </script>
</body>
</html>