<!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 href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<style>
@import url('https://fonts.googleapis.com/css2?family=Amiri:wght@400;700&display=swap');
body { font-family: 'Amiri', serif; }
/* إضافات لتصميم الدائرة المتحركة */
.circle {
position: relative;
width: 100px;
height: 100px;
margin: 0 auto;
}
.circle .wave {
position: absolute;
border-radius: 50%;
border: 5px solid #4CAF50;
opacity: 0;
animation: wave-animation 1.5s infinite ease-out;
}
.circle .wave:nth-child(1) {
animation-delay: 0s;
}
.circle .wave:nth-child(2) {
animation-delay: 0.5s;
}
.circle .wave:nth-child(3) {
animation-delay: 1s;
}
@keyframes wave-animation {
0% {
transform: scale(0.5);
opacity: 0.4;
}
100% {
transform: scale(2.5);
opacity: 0;
}
}
.hidden {
display: none;
}
/* تصميم الرسائل */
.chat-container {
max-height: 50vh;
overflow-y: auto;
padding: 10px;
background-color: #1f2937;
border-radius: 10px;
margin-bottom: 20px;
}
.message {
margin-bottom: 10px;
padding: 10px 15px;
border-radius: 10px;
max-width: 70%;
word-wrap: break-word;
}
.message.user {
background-color: #2563eb;
color: #fff;
align-self: flex-end;
text-align: right;
}
.message.ai {
background-color: #4b5563;
color: #fff;
align-self: flex-start;
text-align: left;
}
</style>
</head>
<body class="bg-gray-900 text-white flex flex-col items-center justify-center min-h-screen">
<h1 class="text-4xl mb-8">محادثة الذكاء الاصطناعي</h1>
<!-- تاريخ المحادثات -->
<div id="chatHistory" class="chat-container flex flex-col w-2/3 mb-4"></div>
<!-- دائرة تصور الصوت -->
<div id="visualizer" class="circle mb-6 hidden">
<div class="wave"></div>
<div class="wave"></div>
<div class="wave"></div>
</div>
<!-- أزرار التحكم -->
<div class="w-2/3">
<button id="talkButton" onclick="toggleChat()"
class="bg-green-500 px-6 py-3 mt-6 rounded hover:bg-green-700 w-full">
🎤 ابدأ المحادثة
</button>
<button id="stopButton" onclick="stopRecognition()"
class="bg-red-500 px-6 py-3 mt-4 rounded hover:bg-red-700 w-full hidden">
⛔ إيقاف المحادثة
</button>
</div>
<script>
let recognizing = false;
let recognition;
let conversationHistory = [];
// تحميل تاريخ المحادثات من الكوكيز
function loadConversationHistory() {
const history = getCookie('conversationHistory');
if (history) {
conversationHistory = JSON.parse(history);
updateChatHistory();
}
}
// تحديث عرض المحادثات
function updateChatHistory() {
const chatHistoryDiv = document.getElementById('chatHistory');
chatHistoryDiv.innerHTML = '';
conversationHistory.forEach(item => {
const messageDiv = document.createElement('div');
messageDiv.className = 'message ' + (item.from === 'user' ? 'user self-end' : 'ai self-start');
messageDiv.innerText = item.text;
chatHistoryDiv.appendChild(messageDiv);
});
chatHistoryDiv.scrollTop = chatHistoryDiv.scrollHeight;
}
// حفظ المحادثات في الكوكيز
function saveConversationHistory() {
setCookie('conversationHistory', JSON.stringify(conversationHistory), 7); // حفظ لمدة 7 أيام
}
function toggleChat() {
if (!recognizing) {
startRecognition();
} else {
stopRecognition();
}
}
function startRecognition() {
recognizing = true;
document.getElementById('visualizer').classList.remove('hidden');
document.getElementById('talkButton').classList.add('hidden');
document.getElementById('stopButton').classList.remove('hidden');
// بدء التعرف على الصوت
recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
recognition.lang = 'ar-SA';
recognition.continuous = false;
recognition.interimResults = false;
recognition.onresult = function(event) {
const userTranscript = event.results[0][0].transcript;
conversationHistory.push({from: 'user', text: userTranscript});
updateChatHistory();
saveConversationHistory();
// هنا يمكنك استدعاء API الخاص بالذكاء الاصطناعي للحصول على الرد
const aiResponse = "هذا رد افتراضي من الذكاء الاصطناعي"; // استبدل هذا بالرد الفعلي
conversationHistory.push({from: 'ai', text: aiResponse});
updateChatHistory();
saveConversationHistory();
stopRecognition();
};
recognition.onerror = function(event) {
console.error('حدث خطأ في التعرف:', event.error);
stopRecognition();
};
recognition.onend = function() {
stopRecognition();
};
recognition.start();
}
function stopRecognition() {
recognizing = false;
document.getElementById('visualizer').classList.add('hidden');
document.getElementById('talkButton').classList.remove('hidden');
document.getElementById('stopButton').classList.add('hidden');
if (recognition) {
recognition.stop();
recognition = null;
}
}
// دوال التعامل مع الكوكيز
function setCookie(name, value, days) {
let expires = "";
if (days) {
const date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
const nameEQ = name + "=";
const ca = document.cookie.split(';');
for(let i=0;i < ca.length;i++) {
let c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
window.onload = function() {
loadConversationHistory();
}
</script>
</body>
</html>
التغييرات التي تم إجراؤها:
-
إزالة اختيار الكتاب: تم حذف قسم اختيار الكتاب بالكامل من الصفحة.
-
تصميم حديث: تم تحديث التصميم باستخدام Tailwind CSS وإضافة تحسينات على الواجهة لجعلها أكثر حداثة وأناقة.
-
إضافة دائرة تصور الصوت: تم إضافة دائرة متحركة تعمل كمؤشر لتصور الصوت أثناء حديث المستخدم أو الذكاء الاصطناعي.
-
تخزين وعرض تاريخ المحادثات: يتم الآن حفظ المحادثات في الكوكيز وعرضها في قسم مخصص لتاريخ المحادثات بطريقة جذابة وسهلة القراءة.
-
تحسين الواجهة: تم التركيز على تحسين تجربة المستخدم من خلال تصميم حديث ومتجاوب مع تحسينات في الألوان والتخطيط.
ملاحظات:
-
تم استخدام نمط CSS لإظهار دائرة متحركة تصور عملية التسجيل أو التحدث، وهذه الدائرة تظهر فقط عند بدء المحادثة وتختفي عند الإيقاف.
-
يتم التعامل مع الكوكيز لتخزين واسترجاع المحادثات السابقة، مما يسمح للمستخدم بالعودة إلى المحادثات السابقة.
-
تم الاحتفاظ بالنصوص الأساسية باللغة العربية والتأكد من الاتجاه من اليمين إلى اليسار لتتناسب مع اللغة العربية.
تنبيه: يجب استبدال الجزء الخاص برد الذكاء الاصطناعي بالمنطق أو API الفعلي الذي يقوم بتوليد الردود بناءً على مدخلات المستخدم.