Update index.html
Browse files- index.html +141 -45
index.html
CHANGED
@@ -7,64 +7,133 @@
|
|
7 |
<style>
|
8 |
body {
|
9 |
font-family: Arial, sans-serif;
|
10 |
-
margin:
|
|
|
11 |
background: #f0f2f5;
|
|
|
|
|
|
|
|
|
12 |
}
|
13 |
.container {
|
14 |
max-width: 600px;
|
15 |
-
|
16 |
background: white;
|
17 |
padding: 20px;
|
18 |
-
border-radius:
|
19 |
-
box-shadow: 0 2px
|
20 |
}
|
21 |
-
button {
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
border: none;
|
25 |
-
padding: 10px 20px;
|
26 |
-
border-radius: 5px;
|
27 |
cursor: pointer;
|
28 |
-
|
|
|
|
|
|
|
|
|
29 |
}
|
30 |
-
button:
|
31 |
-
background: #
|
32 |
}
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
border-radius: 5px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
background: #f8f9fa;
|
|
|
|
|
|
|
38 |
}
|
39 |
-
.label {
|
40 |
font-weight: bold;
|
41 |
color: #666;
|
42 |
-
margin-bottom:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
</style>
|
45 |
</head>
|
46 |
<body>
|
47 |
<div class="container">
|
48 |
-
<
|
49 |
-
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
<div
|
52 |
-
<
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
</div>
|
55 |
|
56 |
-
<div
|
57 |
-
<div class="label">رد النموذج:</div>
|
58 |
-
<div id="modelResponse"></div>
|
59 |
</div>
|
60 |
</div>
|
61 |
|
62 |
<script>
|
63 |
const API_URL = 'https://8o1mzdgh9f40t4-7777.proxy.runpod.net/proxy/8000/chat';
|
64 |
-
const
|
65 |
-
const
|
66 |
const spokenText = document.getElementById('spokenText');
|
67 |
const modelResponse = document.getElementById('modelResponse');
|
|
|
|
|
|
|
68 |
|
69 |
// إعداد التعرف على الكلام
|
70 |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
@@ -72,12 +141,29 @@
|
|
72 |
recognition.continuous = false;
|
73 |
recognition.interimResults = false;
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
recognition.onresult = async (event) => {
|
76 |
const text = event.results[0][0].transcript;
|
77 |
spokenText.textContent = text;
|
78 |
|
79 |
try {
|
80 |
-
// إرسال النص إلى النموذج
|
81 |
const response = await fetch(API_URL, {
|
82 |
method: 'POST',
|
83 |
headers: {
|
@@ -92,36 +178,46 @@
|
|
92 |
|
93 |
// تحويل الرد إلى صوت
|
94 |
const utterance = new SpeechSynthesisUtterance(botReply);
|
|
|
|
|
|
|
95 |
utterance.lang = 'ar-SA';
|
|
|
|
|
96 |
speechSynthesis.speak(utterance);
|
97 |
} catch (error) {
|
98 |
modelResponse.textContent = 'حدث خطأ في الاتصال بالنموذج';
|
|
|
99 |
}
|
100 |
};
|
101 |
|
102 |
recognition.onerror = (event) => {
|
103 |
console.error('خطأ:', event.error);
|
104 |
-
|
|
|
|
|
105 |
};
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
spokenText.textContent = '';
|
112 |
-
modelResponse.textContent = '';
|
113 |
-
};
|
114 |
-
|
115 |
-
stopBtn.onclick = () => {
|
116 |
-
recognition.stop();
|
117 |
-
startBtn.disabled = false;
|
118 |
-
stopBtn.disabled = true;
|
119 |
};
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
};
|
126 |
</script>
|
127 |
</body>
|
|
|
7 |
<style>
|
8 |
body {
|
9 |
font-family: Arial, sans-serif;
|
10 |
+
margin: 0;
|
11 |
+
padding: 20px;
|
12 |
background: #f0f2f5;
|
13 |
+
min-height: 100vh;
|
14 |
+
display: flex;
|
15 |
+
flex-direction: column;
|
16 |
+
align-items: center;
|
17 |
}
|
18 |
.container {
|
19 |
max-width: 600px;
|
20 |
+
width: 100%;
|
21 |
background: white;
|
22 |
padding: 20px;
|
23 |
+
border-radius: 15px;
|
24 |
+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
25 |
}
|
26 |
+
.record-button-container {
|
27 |
+
display: flex;
|
28 |
+
justify-content: center;
|
29 |
+
align-items: center;
|
30 |
+
margin: 20px 0;
|
31 |
+
}
|
32 |
+
.record-button {
|
33 |
+
width: 150px;
|
34 |
+
height: 150px;
|
35 |
+
border-radius: 50%;
|
36 |
+
background: #f0f2f5;
|
37 |
border: none;
|
|
|
|
|
38 |
cursor: pointer;
|
39 |
+
display: flex;
|
40 |
+
align-items: center;
|
41 |
+
justify-content: center;
|
42 |
+
position: relative;
|
43 |
+
transition: all 0.3s ease;
|
44 |
}
|
45 |
+
.record-button:hover {
|
46 |
+
background: #e4e6e9;
|
47 |
}
|
48 |
+
.record-button.recording {
|
49 |
+
background: #ff4444;
|
50 |
+
}
|
51 |
+
.record-button.recording .inner-circle {
|
52 |
+
background: white;
|
53 |
+
width: 50px;
|
54 |
+
height: 50px;
|
55 |
border-radius: 5px;
|
56 |
+
}
|
57 |
+
.inner-circle {
|
58 |
+
width: 60px;
|
59 |
+
height: 60px;
|
60 |
+
background: #ff4444;
|
61 |
+
border-radius: 50%;
|
62 |
+
transition: all 0.3s ease;
|
63 |
+
}
|
64 |
+
.status-text {
|
65 |
+
text-align: center;
|
66 |
+
margin: 10px 0;
|
67 |
+
color: #666;
|
68 |
+
font-size: 14px;
|
69 |
+
}
|
70 |
+
.message-container {
|
71 |
background: #f8f9fa;
|
72 |
+
padding: 15px;
|
73 |
+
border-radius: 10px;
|
74 |
+
margin: 10px 0;
|
75 |
}
|
76 |
+
.message-label {
|
77 |
font-weight: bold;
|
78 |
color: #666;
|
79 |
+
margin-bottom: 8px;
|
80 |
+
}
|
81 |
+
.message-content {
|
82 |
+
padding: 10px;
|
83 |
+
background: white;
|
84 |
+
border-radius: 8px;
|
85 |
+
min-height: 40px;
|
86 |
+
}
|
87 |
+
.voice-settings {
|
88 |
+
margin-top: 20px;
|
89 |
+
padding: 15px;
|
90 |
+
background: #f8f9fa;
|
91 |
+
border-radius: 10px;
|
92 |
+
}
|
93 |
+
select {
|
94 |
+
width: 100%;
|
95 |
+
padding: 8px;
|
96 |
+
margin: 5px 0;
|
97 |
+
border-radius: 5px;
|
98 |
+
border: 1px solid #ddd;
|
99 |
}
|
100 |
</style>
|
101 |
</head>
|
102 |
<body>
|
103 |
<div class="container">
|
104 |
+
<div class="record-button-container">
|
105 |
+
<button class="record-button" id="recordButton">
|
106 |
+
<div class="inner-circle"></div>
|
107 |
+
</button>
|
108 |
+
</div>
|
109 |
+
<div class="status-text" id="statusText">انقر للبدء في التسجيل</div>
|
110 |
|
111 |
+
<div class="voice-settings">
|
112 |
+
<select id="voiceSelect">
|
113 |
+
<option value="">اختر صوت رجل عربي فصحى</option>
|
114 |
+
</select>
|
115 |
+
</div>
|
116 |
+
|
117 |
+
<div class="message-container">
|
118 |
+
<div class="message-label">ما قلته:</div>
|
119 |
+
<div class="message-content" id="spokenText"></div>
|
120 |
</div>
|
121 |
|
122 |
+
<div class="message-container">
|
123 |
+
<div class="message-label">رد النموذج:</div>
|
124 |
+
<div class="message-content" id="modelResponse"></div>
|
125 |
</div>
|
126 |
</div>
|
127 |
|
128 |
<script>
|
129 |
const API_URL = 'https://8o1mzdgh9f40t4-7777.proxy.runpod.net/proxy/8000/chat';
|
130 |
+
const recordButton = document.getElementById('recordButton');
|
131 |
+
const statusText = document.getElementById('statusText');
|
132 |
const spokenText = document.getElementById('spokenText');
|
133 |
const modelResponse = document.getElementById('modelResponse');
|
134 |
+
const voiceSelect = document.getElementById('voiceSelect');
|
135 |
+
|
136 |
+
let isRecording = false;
|
137 |
|
138 |
// إعداد التعرف على الكلام
|
139 |
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
|
|
141 |
recognition.continuous = false;
|
142 |
recognition.interimResults = false;
|
143 |
|
144 |
+
// تحميل الأصوات العربية
|
145 |
+
function loadVoices() {
|
146 |
+
const voices = speechSynthesis.getVoices();
|
147 |
+
voiceSelect.innerHTML = '<option value="">اختر صوت رجل عربي فصحى</option>';
|
148 |
+
|
149 |
+
voices.forEach((voice, index) => {
|
150 |
+
if (voice.lang.includes('ar') && voice.name.includes('Male')) {
|
151 |
+
const option = document.createElement('option');
|
152 |
+
option.value = index;
|
153 |
+
option.textContent = voice.name;
|
154 |
+
voiceSelect.appendChild(option);
|
155 |
+
}
|
156 |
+
});
|
157 |
+
}
|
158 |
+
|
159 |
+
speechSynthesis.onvoiceschanged = loadVoices;
|
160 |
+
loadVoices();
|
161 |
+
|
162 |
recognition.onresult = async (event) => {
|
163 |
const text = event.results[0][0].transcript;
|
164 |
spokenText.textContent = text;
|
165 |
|
166 |
try {
|
|
|
167 |
const response = await fetch(API_URL, {
|
168 |
method: 'POST',
|
169 |
headers: {
|
|
|
178 |
|
179 |
// تحويل الرد إلى صوت
|
180 |
const utterance = new SpeechSynthesisUtterance(botReply);
|
181 |
+
const voices = speechSynthesis.getVoices();
|
182 |
+
const selectedVoice = voices[voiceSelect.value || 0];
|
183 |
+
utterance.voice = selectedVoice;
|
184 |
utterance.lang = 'ar-SA';
|
185 |
+
utterance.rate = 1;
|
186 |
+
utterance.pitch = 1;
|
187 |
speechSynthesis.speak(utterance);
|
188 |
} catch (error) {
|
189 |
modelResponse.textContent = 'حدث خطأ في الاتصال بالنموذج';
|
190 |
+
statusText.textContent = 'حدث خطأ في الاتصال';
|
191 |
}
|
192 |
};
|
193 |
|
194 |
recognition.onerror = (event) => {
|
195 |
console.error('خطأ:', event.error);
|
196 |
+
statusText.textContent = 'حدث خطأ في التعرف على الكلام';
|
197 |
+
isRecording = false;
|
198 |
+
recordButton.classList.remove('recording');
|
199 |
};
|
200 |
|
201 |
+
recognition.onend = () => {
|
202 |
+
isRecording = false;
|
203 |
+
recordButton.classList.remove('recording');
|
204 |
+
statusText.textContent = 'انقر للبدء في التسجيل';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
};
|
206 |
|
207 |
+
recordButton.onclick = () => {
|
208 |
+
if (!isRecording) {
|
209 |
+
recognition.start();
|
210 |
+
isRecording = true;
|
211 |
+
recordButton.classList.add('recording');
|
212 |
+
statusText.textContent = 'جارٍ التسجيل... انقر للإيقاف';
|
213 |
+
spokenText.textContent = '';
|
214 |
+
modelResponse.textContent = '';
|
215 |
+
} else {
|
216 |
+
recognition.stop();
|
217 |
+
isRecording = false;
|
218 |
+
recordButton.classList.remove('recording');
|
219 |
+
statusText.textContent = 'جارٍ معالجة الكلام...';
|
220 |
+
}
|
221 |
};
|
222 |
</script>
|
223 |
</body>
|