deepsite-project / voice.html
wamd's picture
import requests
6db5c41 verified
<!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 rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@400;700&display=swap" rel="stylesheet">
</head>
<body>
<div class="container">
<header>
<h1>منصة لَـهْجة</h1>
<p>توليد الصوت باللهجة النجدية</p>
</header>
<div class="voice-box">
<textarea id="textInput" placeholder="اكتب النص الذي تريد تحويله إلى صوت..."></textarea>
<div class="controls">
<select id="voiceSelect">
<option value="alloy">صوت رجالي</option>
<option value="echo">صوت نسائي</option>
</select>
<button id="generateBtn">توليد الصوت</button>
</div>
<div class="audio-container" id="audioContainer" style="display: none;">
<audio id="audioPlayer" controls></audio>
<a id="downloadLink" class="btn">تحميل الصوت</a>
</div>
</div>
</div>
<script>
document.getElementById('generateBtn').addEventListener('click', async function() {
const text = document.getElementById('textInput').value;
const voice = document.getElementById('voiceSelect').value;
if (!text) {
alert('الرجاء إدخال نص');
return;
}
try {
const response = await fetch('/generate-voice', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: text,
voice: voice
})
});
if (response.ok) {
const blob = await response.blob();
const audioUrl = URL.createObjectURL(blob);
const audioPlayer = document.getElementById('audioPlayer');
const audioContainer = document.getElementById('audioContainer');
const downloadLink = document.getElementById('downloadLink');
audioPlayer.src = audioUrl;
audioContainer.style.display = 'block';
downloadLink.href = audioUrl;
downloadLink.download = 'lahja-voice.wav';
audioPlayer.play();
} else {
alert('حدث خطأ أثناء توليد الصوت');
}
} catch (error) {
console.error('Error:', error);
alert('حدث خطأ أثناء الاتصال بالخادم');
}
});
</script>
</body>
</html>