Spaces:
Running
import requests
Browse filesimport os
# احصل على مفتاح الـ API من متغير البيئة
AZURE_API_KEY = "4AwsIf87cyBIgaJVsy0phWUQdZFcbrJxpQBDQNzL4xjcP2MFzrrYJQQJ99BIACHYHv6XJ3w3AAAAACOGYrzM"
# رابط الـ endpoint
url = "https://lahja-dev-resource.cognitiveservices.azure.com/openai/deployments/LAHJA-V1/audio/speech?api-version=2025-03-01-preview"
# جسم الطلب
data = {
"model": "LAHJA-V1",
"input": "أنا مساعد افتراضي ذكي أتكلم باللهجة النجدية، أقدر أساعدك في المعلومات التقنية، الاستفسارات، أو أي موضوع تبي تعرف عنه. وش اللي بخاطرك؟ 😊",
"voice": "alloy",
# "speed":0.9
}
# الرؤوس
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {AZURE_API_KEY}"
}
# إرسال الطلب
response = requests.post(url, json=data, headers=headers)
# حفظ الملف الصوتي لو نجح
if response.status_code == 200:
with open("output_audio.wav", "wb") as f:
f.write(response.content)
print("تم حفظ الصوت في output_audio.wav")
else:
print(f"فشل الطلب: {response.status_code}")
print(response.text)
- index.html +6 -6
- style.css +109 -17
- voice.html +79 -0
|
@@ -5,15 +5,15 @@
|
|
| 5 |
<meta name="viewport" content="width=device-width" />
|
| 6 |
<title>My static Space</title>
|
| 7 |
<link rel="stylesheet" href="style.css" />
|
| 8 |
-
|
|
|
|
| 9 |
<body>
|
| 10 |
<div class="card">
|
| 11 |
-
<h1
|
| 12 |
-
<p
|
| 13 |
<p>
|
| 14 |
-
|
| 15 |
-
<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
|
| 16 |
</p>
|
| 17 |
</div>
|
| 18 |
-
|
| 19 |
</html>
|
|
|
|
| 5 |
<meta name="viewport" content="width=device-width" />
|
| 6 |
<title>My static Space</title>
|
| 7 |
<link rel="stylesheet" href="style.css" />
|
| 8 |
+
<link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@400;700&display=swap" rel="stylesheet">
|
| 9 |
+
</head>
|
| 10 |
<body>
|
| 11 |
<div class="card">
|
| 12 |
+
<h1>مرحباً بكم في منصة لَـهْجة</h1>
|
| 13 |
+
<p>منصة تفاعلية لتوليد الأصوات باللهجة النجدية</p>
|
| 14 |
<p>
|
| 15 |
+
<a href="voice.html" class="btn">تجربة المنصة</a>
|
|
|
|
| 16 |
</p>
|
| 17 |
</div>
|
| 18 |
+
</body>
|
| 19 |
</html>
|
|
@@ -1,28 +1,120 @@
|
|
|
|
|
| 1 |
body {
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
}
|
| 5 |
|
| 6 |
h1 {
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
margin-bottom: 10px;
|
| 15 |
-
margin-top: 5px;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
border-radius: 16px;
|
| 24 |
}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```css
|
| 2 |
body {
|
| 3 |
+
font-family: 'Tajawal', sans-serif;
|
| 4 |
+
background-color: #f5f5f5;
|
| 5 |
+
margin: 0;
|
| 6 |
+
padding: 0;
|
| 7 |
+
line-height: 1.6;
|
| 8 |
+
color: #333;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
.container {
|
| 12 |
+
max-width: 800px;
|
| 13 |
+
margin: 0 auto;
|
| 14 |
+
padding: 20px;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
header {
|
| 18 |
+
text-align: center;
|
| 19 |
+
margin-bottom: 30px;
|
| 20 |
}
|
| 21 |
|
| 22 |
h1 {
|
| 23 |
+
color: #2c3e50;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
.voice-box {
|
| 27 |
+
background: white;
|
| 28 |
+
padding: 25px;
|
| 29 |
+
border-radius: 8px;
|
| 30 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
textarea {
|
| 34 |
+
width: 100%;
|
| 35 |
+
min-height: 150px;
|
| 36 |
+
padding: 10px;
|
| 37 |
+
margin-bottom: 15px;
|
| 38 |
+
border: 1px solid #ddd;
|
| 39 |
+
border-radius: 4px;
|
| 40 |
+
font-family: inherit;
|
| 41 |
+
font-size: 16px;
|
| 42 |
+
resize: vertical;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.controls {
|
| 46 |
+
display: flex;
|
| 47 |
+
gap: 10px;
|
| 48 |
+
margin-bottom: 20px;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
select, button {
|
| 52 |
+
padding: 10px 15px;
|
| 53 |
+
border: none;
|
| 54 |
+
border-radius: 4px;
|
| 55 |
+
font-family: inherit;
|
| 56 |
+
font-size: 16px;
|
| 57 |
}
|
| 58 |
|
| 59 |
+
select {
|
| 60 |
+
flex: 1;
|
| 61 |
+
background-color: #f8f9fa;
|
|
|
|
|
|
|
| 62 |
}
|
| 63 |
|
| 64 |
+
button {
|
| 65 |
+
background-color: #3498db;
|
| 66 |
+
color: white;
|
| 67 |
+
cursor: pointer;
|
| 68 |
+
transition: background-color 0.3s;
|
|
|
|
| 69 |
}
|
| 70 |
|
| 71 |
+
button:hover {
|
| 72 |
+
background-color: #2980b9;
|
| 73 |
}
|
| 74 |
+
|
| 75 |
+
.audio-container {
|
| 76 |
+
margin-top: 20px;
|
| 77 |
+
display: flex;
|
| 78 |
+
flex-direction: column;
|
| 79 |
+
gap: 15px;
|
| 80 |
+
align-items: center;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
audio {
|
| 84 |
+
width: 100%;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
.btn {
|
| 88 |
+
display: inline-block;
|
| 89 |
+
padding: 8px 16px;
|
| 90 |
+
background-color: #2ecc71;
|
| 91 |
+
color: white;
|
| 92 |
+
text-decoration: none;
|
| 93 |
+
border-radius: 4px;
|
| 94 |
+
transition: background-color 0.3s;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
.btn:hover {
|
| 98 |
+
background-color: #27ae60;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
@media (max-width: 600px) {
|
| 102 |
+
.controls {
|
| 103 |
+
flex-direction: column;
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
You'll also need to create a Python backend (app.py) to handle the API requests, but I'll provide that separately if you need it. The current implementation includes:
|
| 109 |
+
1. Updated index.html with Arabic welcome message and link to voice generator
|
| 110 |
+
2. New voice.html page with voice generation interface
|
| 111 |
+
3. New style.css with responsive design and Arabic font support
|
| 112 |
+
|
| 113 |
+
The voice generation page features:
|
| 114 |
+
- Text input area
|
| 115 |
+
- Voice selection dropdown
|
| 116 |
+
- Generate button
|
| 117 |
+
- Audio player
|
| 118 |
+
- Download option
|
| 119 |
+
- Responsive design for mobile devices
|
| 120 |
+
- RTL support for Arabic text
|
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="ar" dir="rtl">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>منصة لَـهْجة - توليد الصوت</title>
|
| 7 |
+
<link rel="stylesheet" href="style.css">
|
| 8 |
+
<link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@400;700&display=swap" rel="stylesheet">
|
| 9 |
+
</head>
|
| 10 |
+
<body>
|
| 11 |
+
<div class="container">
|
| 12 |
+
<header>
|
| 13 |
+
<h1>منصة لَـهْجة</h1>
|
| 14 |
+
<p>توليد الصوت باللهجة النجدية</p>
|
| 15 |
+
</header>
|
| 16 |
+
|
| 17 |
+
<div class="voice-box">
|
| 18 |
+
<textarea id="textInput" placeholder="اكتب النص الذي تريد تحويله إلى صوت..."></textarea>
|
| 19 |
+
<div class="controls">
|
| 20 |
+
<select id="voiceSelect">
|
| 21 |
+
<option value="alloy">صوت رجالي</option>
|
| 22 |
+
<option value="echo">صوت نسائي</option>
|
| 23 |
+
</select>
|
| 24 |
+
<button id="generateBtn">توليد الصوت</button>
|
| 25 |
+
</div>
|
| 26 |
+
<div class="audio-container" id="audioContainer" style="display: none;">
|
| 27 |
+
<audio id="audioPlayer" controls></audio>
|
| 28 |
+
<a id="downloadLink" class="btn">تحميل الصوت</a>
|
| 29 |
+
</div>
|
| 30 |
+
</div>
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
<script>
|
| 34 |
+
document.getElementById('generateBtn').addEventListener('click', async function() {
|
| 35 |
+
const text = document.getElementById('textInput').value;
|
| 36 |
+
const voice = document.getElementById('voiceSelect').value;
|
| 37 |
+
|
| 38 |
+
if (!text) {
|
| 39 |
+
alert('الرجاء إدخال نص');
|
| 40 |
+
return;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
try {
|
| 44 |
+
const response = await fetch('/generate-voice', {
|
| 45 |
+
method: 'POST',
|
| 46 |
+
headers: {
|
| 47 |
+
'Content-Type': 'application/json',
|
| 48 |
+
},
|
| 49 |
+
body: JSON.stringify({
|
| 50 |
+
text: text,
|
| 51 |
+
voice: voice
|
| 52 |
+
})
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
if (response.ok) {
|
| 56 |
+
const blob = await response.blob();
|
| 57 |
+
const audioUrl = URL.createObjectURL(blob);
|
| 58 |
+
|
| 59 |
+
const audioPlayer = document.getElementById('audioPlayer');
|
| 60 |
+
const audioContainer = document.getElementById('audioContainer');
|
| 61 |
+
const downloadLink = document.getElementById('downloadLink');
|
| 62 |
+
|
| 63 |
+
audioPlayer.src = audioUrl;
|
| 64 |
+
audioContainer.style.display = 'block';
|
| 65 |
+
downloadLink.href = audioUrl;
|
| 66 |
+
downloadLink.download = 'lahja-voice.wav';
|
| 67 |
+
|
| 68 |
+
audioPlayer.play();
|
| 69 |
+
} else {
|
| 70 |
+
alert('حدث خطأ أثناء توليد الصوت');
|
| 71 |
+
}
|
| 72 |
+
} catch (error) {
|
| 73 |
+
console.error('Error:', error);
|
| 74 |
+
alert('حدث خطأ أثناء الاتصال بالخادم');
|
| 75 |
+
}
|
| 76 |
+
});
|
| 77 |
+
</script>
|
| 78 |
+
</body>
|
| 79 |
+
</html>
|