File size: 9,954 Bytes
3f5d3d8 835a507 3f5d3d8 12f504a 280525f 27fbe7f 12f504a 3f5d3d8 27fbe7f 12f504a 280525f 3f5d3d8 12f504a 280525f 12f504a 280525f 12f504a 280525f 12f504a 280525f 3f5d3d8 12f504a 280525f 20709bb 12f504a 280525f 3f5d3d8 12f504a 280525f 12f504a 280525f 12f504a 280525f 12f504a 280525f 12f504a 280525f 12f504a 280525f 12f504a 280525f 12f504a 280525f 20709bb 12f504a 27fbe7f 12f504a 280525f 12f504a 280525f 12f504a 280525f 12f504a 280525f 3f5d3d8 27fbe7f 280525f 12f504a 27fbe7f 280525f 3f5d3d8 12f504a 27fbe7f 12f504a 280525f 12f504a 280525f 27fbe7f 835a507 27fbe7f 12f504a 27fbe7f 3f5d3d8 27fbe7f 3f5d3d8 27fbe7f 3f5d3d8 27fbe7f 3f5d3d8 27fbe7f 12f504a 835a507 12f504a 27fbe7f 12f504a 20709bb 27fbe7f 12f504a 3f5d3d8 12f504a 27fbe7f 20709bb 12f504a 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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
<!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: 0;
padding: 0;
background: #f0f2f5;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
}
.container {
width: 100%;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
.record-button-container {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(135deg, #6e8efb, #4a6cf7);
}
.record-button {
width: 80vmin;
height: 80vmin;
border-radius: 50%;
background: rgba(255, 255, 255, 0.1);
border: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
position: relative;
transition: all 0.3s ease;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
backdrop-filter: blur(5px);
}
.record-button:hover {
transform: scale(1.02);
box-shadow: 0 15px 40px rgba(0,0,0,0.3);
}
.record-button.recording {
background: rgba(255, 68, 68, 0.2);
animation: pulse 2s infinite;
}
.record-button.recording .inner-circle {
background: #ff4444;
transform: scale(0.8);
}
.inner-circle {
width: 40%;
height: 40%;
background: #ffffff;
border-radius: 50%;
transition: all 0.3s ease;
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
.status-text {
position: absolute;
bottom: 10%;
text-align: center;
color: white;
font-size: 1.5rem;
font-weight: bold;
text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.toggle-code-button {
position: fixed;
top: 20px;
right: 20px;
padding: 10px 20px;
background: rgba(255, 255, 255, 0.2);
border: none;
border-radius: 25px;
color: white;
cursor: pointer;
backdrop-filter: blur(5px);
transition: all 0.3s ease;
z-index: 1000;
}
.toggle-code-button:hover {
background: rgba(255, 255, 255, 0.3);
}
.code-section {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.95);
z-index: 999;
overflow-y: auto;
padding: 20px;
box-sizing: border-box;
}
.code-section.visible {
display: block;
}
.message-container {
background: rgba(255, 255, 255, 0.1);
padding: 15px;
border-radius: 15px;
margin: 10px;
backdrop-filter: blur(5px);
color: white;
width: 90%;
max-width: 600px;
}
.message-label {
font-weight: bold;
margin-bottom: 8px;
}
.message-content {
padding: 10px;
background: rgba(255, 255, 255, 0.05);
border-radius: 8px;
min-height: 40px;
}
.voice-settings {
position: fixed;
bottom: 20px;
width: 90%;
max-width: 600px;
padding: 15px;
background: rgba(255, 255, 255, 0.1);
border-radius: 15px;
backdrop-filter: blur(5px);
}
select {
width: 100%;
padding: 12px;
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.1);
color: white;
font-size: 16px;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
</style>
</head>
<body>
<div class="container">
<button class="toggle-code-button" id="toggleCode">عرض النص</button>
<div class="record-button-container">
<button class="record-button" id="recordButton">
<div class="inner-circle"></div>
</button>
</div>
<div class="status-text" id="statusText">انقر للبدء في التسجيل</div>
<div class="code-section" id="codeSection">
<div class="message-container">
<div class="message-label">ما قلته:</div>
<div class="message-content" id="spokenText"></div>
</div>
<div class="message-container">
<div class="message-label">رد النموذج:</div>
<div class="message-content" id="modelResponse"></div>
</div>
<div class="voice-settings">
<select id="voiceSelect">
<option value="">اختر صوت رجل عربي فصحى</option>
</select>
</div>
</div>
</div>
<script>
const API_URL = 'https://8o1mzdgh9f40t4-7777.proxy.runpod.net/proxy/8000/chat';
const recordButton = document.getElementById('recordButton');
const statusText = document.getElementById('statusText');
const spokenText = document.getElementById('spokenText');
const modelResponse = document.getElementById('modelResponse');
const voiceSelect = document.getElementById('voiceSelect');
const toggleCodeButton = document.getElementById('toggleCode');
const codeSection = document.getElementById('codeSection');
let isRecording = false;
toggleCodeButton.onclick = () => {
codeSection.classList.toggle('visible');
toggleCodeButton.textContent = codeSection.classList.contains('visible') ? 'إخفاء النص' : 'عرض النص';
};
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
recognition.lang = 'ar-SA';
recognition.continuous = false;
recognition.interimResults = false;
function loadVoices() {
const voices = speechSynthesis.getVoices();
voiceSelect.innerHTML = '<option value="">اختر صوت رجل عربي فصحى</option>';
voices.forEach((voice, index) => {
if (voice.lang.includes('ar') && voice.name.includes('Male')) {
const option = document.createElement('option');
option.value = index;
option.textContent = voice.name;
voiceSelect.appendChild(option);
}
});
}
speechSynthesis.onvoiceschanged = loadVoices;
loadVoices();
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.value || 0];
utterance.voice = selectedVoice;
utterance.lang = 'ar-SA';
utterance.rate = 1;
utterance.pitch = 1;
speechSynthesis.speak(utterance);
} catch (error) {
modelResponse.textContent = 'حدث خطأ في الاتصال بالنموذج';
statusText.textContent = 'حدث خطأ في الاتصال';
}
};
recognition.onerror = (event) => {
console.error('خطأ:', event.error);
statusText.textContent = 'حدث خطأ في التعرف على الكلام';
isRecording = false;
recordButton.classList.remove('recording');
};
recognition.onend = () => {
isRecording = false;
recordButton.classList.remove('recording');
statusText.textContent = 'انقر للبدء في التسجيل';
};
recordButton.onclick = () => {
if (!isRecording) {
recognition.start();
isRecording = true;
recordButton.classList.add('recording');
statusText.textContent = 'جارٍ التسجيل... انقر للإيقاف';
spokenText.textContent = '';
modelResponse.textContent = '';
} else {
recognition.stop();
isRecording = false;
recordButton.classList.remove('recording');
statusText.textContent = 'جارٍ معالجة الكلام...';
}
};
</script>
</body>
</html> |