test11 / index.html
joermd's picture
Update index.html
27fbe7f verified
raw
history blame
4.14 kB
<!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;
}
</style>
</head>
<body>
<div class="container">
<button id="startBtn">ابدأ التحدث</button>
<button id="stopBtn" disabled>توقف</button>
<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 recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
recognition.lang = 'ar-SA';
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);
utterance.lang = 'ar-SA';
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>