Spaces:
Running
Running
Update index.html
Browse files- index.html +131 -126
index.html
CHANGED
|
@@ -3,93 +3,112 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Hand Pose Classifier -
|
| 7 |
|
| 8 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script>
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
|
| 10 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
|
| 11 |
|
| 12 |
<style>
|
|
|
|
| 13 |
body {
|
| 14 |
-
background
|
| 15 |
-
color:
|
| 16 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 17 |
display: flex;
|
| 18 |
flex-direction: column;
|
| 19 |
align-items: center;
|
| 20 |
-
margin
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
position: relative;
|
| 24 |
-
margin-top: 20px;
|
| 25 |
-
}
|
| 26 |
-
/* Canvas dengan efek neon biru */
|
| 27 |
-
canvas {
|
| 28 |
-
border: 2px solid #3b82f6;
|
| 29 |
-
box-shadow: 0 0 20px #3b82f6;
|
| 30 |
-
border-radius: 12px;
|
| 31 |
-
background-color: #000;
|
| 32 |
-
/* Optimasi Speed: Gunakan resolusi rendah untuk pemrosesan */
|
| 33 |
-
width: 320px;
|
| 34 |
-
height: 240px;
|
| 35 |
-
}
|
| 36 |
-
#responGif {
|
| 37 |
-
position: absolute;
|
| 38 |
-
top: 50%;
|
| 39 |
-
left: 50%;
|
| 40 |
-
transform: translate(-50%, -50%);
|
| 41 |
-
display: none;
|
| 42 |
-
border-radius: 10px;
|
| 43 |
-
z-index: 10;
|
| 44 |
-
width: 150px; /* Diperkecil agar tidak menutupi tangan */
|
| 45 |
-
border: 3px solid #ec4899; /* Neon pink border */
|
| 46 |
}
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
color: white;
|
| 50 |
border: none;
|
| 51 |
-
padding:
|
| 52 |
-
font-size:
|
| 53 |
-
border-radius:
|
| 54 |
cursor: pointer;
|
| 55 |
-
margin-bottom: 10px;
|
| 56 |
font-weight: bold;
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
}
|
| 59 |
-
button:hover { background-color: #2563eb; }
|
| 60 |
#statusPose {
|
| 61 |
-
font-size:
|
| 62 |
font-weight: bold;
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
}
|
| 66 |
</style>
|
| 67 |
</head>
|
| 68 |
<body>
|
| 69 |
|
| 70 |
-
<h2>
|
| 71 |
-
<p>
|
| 72 |
|
| 73 |
-
<button id="startBtn">Mulai
|
| 74 |
|
| 75 |
-
<div id="
|
|
|
|
|
|
|
| 76 |
|
| 77 |
<div class="monitor-container">
|
| 78 |
<video id="videoElement" style="display: none;" autoplay playsinline></video>
|
| 79 |
-
<canvas id="outputCanvas" width="
|
| 80 |
-
<img id="responGif" src="animasi.gif" alt="Respon AI">
|
| 81 |
</div>
|
| 82 |
|
| 83 |
-
<audio id="audio1" src="suara1.mp3"></audio>
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
const videoElement = document.getElementById('videoElement');
|
| 86 |
const canvasElement = document.getElementById('outputCanvas');
|
| 87 |
const canvasCtx = canvasElement.getContext('2d');
|
| 88 |
-
const responGif = document.getElementById('responGif');
|
| 89 |
const startBtn = document.getElementById('startBtn');
|
| 90 |
const statusPose = document.getElementById('statusPose');
|
| 91 |
|
| 92 |
-
// Menampung 5 audio dalam array agar mudah dikelola
|
| 93 |
const sounds = [
|
| 94 |
document.getElementById('audio1'),
|
| 95 |
document.getElementById('audio2'),
|
|
@@ -98,75 +117,66 @@
|
|
| 98 |
document.getElementById('audio5')
|
| 99 |
];
|
| 100 |
|
| 101 |
-
let
|
| 102 |
-
let isProcessingGesture = false; // Mencegah spam suara saat pose masih ditahan
|
| 103 |
|
| 104 |
-
//
|
| 105 |
-
// Mencari jarak Euclidean antara dua titik
|
| 106 |
function getDistance(p1, p2) {
|
| 107 |
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
| 108 |
}
|
| 109 |
|
|
|
|
| 110 |
function classifyPose(landmarks) {
|
| 111 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
-
//
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
// Logika Thumb sedikit beda karena gerakannya horizontal.
|
| 121 |
-
// Kita cek jarak horizontal ujung jempol (4) ke pangkal jari telunjuk (5)
|
| 122 |
-
const thumbExtended = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 123 |
-
|
| 124 |
-
// --- Mulai Klasifikasi Berdasarkan Aturan ---
|
| 125 |
-
|
| 126 |
-
// Pose 5: FIST (Kepalan) - Semua jari tertutup rapat
|
| 127 |
-
if (!indexExtended && !middleExtended && !ringExtended && !pinkyExtended) {
|
| 128 |
-
return { id: 5, name: "5. Kepalan Jari (Fist)" };
|
| 129 |
}
|
| 130 |
|
| 131 |
-
//
|
| 132 |
-
if (
|
| 133 |
-
return { id: 4, name: "
|
| 134 |
}
|
| 135 |
|
| 136 |
-
//
|
| 137 |
-
if (
|
| 138 |
-
return { id: 2, name: "
|
| 139 |
}
|
| 140 |
|
| 141 |
-
//
|
| 142 |
-
if (
|
| 143 |
-
return { id: 1, name: "
|
| 144 |
}
|
| 145 |
|
| 146 |
-
//
|
| 147 |
-
const
|
| 148 |
-
if (
|
| 149 |
-
return { id: 3, name: "
|
| 150 |
}
|
| 151 |
|
| 152 |
-
return null; //
|
| 153 |
}
|
| 154 |
|
| 155 |
-
//
|
| 156 |
const hands = new Hands({locateFile: (file) => {
|
| 157 |
return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`;
|
| 158 |
}});
|
| 159 |
|
| 160 |
hands.setOptions({
|
| 161 |
-
maxNumHands: 1,
|
| 162 |
-
modelComplexity:
|
| 163 |
-
minDetectionConfidence: 0.7,
|
| 164 |
-
minTrackingConfidence: 0.
|
| 165 |
});
|
| 166 |
|
| 167 |
-
// --- LOGIKA UTAMA (ON RESULTS) ---
|
| 168 |
hands.onResults((results) => {
|
| 169 |
-
// Gambar Canvas
|
| 170 |
canvasCtx.save();
|
| 171 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 172 |
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
|
|
@@ -175,64 +185,59 @@
|
|
| 175 |
|
| 176 |
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
|
| 177 |
for (const landmarks of results.multiHandLandmarks) {
|
| 178 |
-
// Gambar kerangka
|
| 179 |
-
drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: '#ec4899', lineWidth:
|
| 180 |
-
drawLandmarks(canvasCtx, landmarks, {color: '#
|
| 181 |
|
| 182 |
-
// Lakukan klasifikasi pose
|
| 183 |
detectedPose = classifyPose(landmarks);
|
| 184 |
}
|
| 185 |
}
|
| 186 |
canvasCtx.restore();
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
// Logika Trigger Suara dan GIF
|
| 191 |
if (detectedPose) {
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
if (!isProcessingGesture && (currentTime - lastTriggerTime > 3)) {
|
| 196 |
-
isProcessingGesture = true;
|
| 197 |
-
lastTriggerTime = currentTime;
|
| 198 |
-
|
| 199 |
-
// Tampilkan Respon Visual
|
| 200 |
-
responGif.style.display = 'block';
|
| 201 |
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
const soundToPlay = sounds[detectedPose.id - 1];
|
| 204 |
-
if (soundToPlay)
|
| 205 |
-
soundToPlay.currentTime = 0; // Reset ke awal
|
| 206 |
-
soundToPlay.play();
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
// Sembunyikan GIF setelah 2 detik dan izinkan deteksi pose baru
|
| 210 |
-
setTimeout(() => {
|
| 211 |
-
responGif.style.display = 'none';
|
| 212 |
-
isProcessingGesture = false;
|
| 213 |
-
}, 2000);
|
| 214 |
}
|
|
|
|
| 215 |
} else {
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
}
|
| 218 |
});
|
| 219 |
|
| 220 |
-
//
|
| 221 |
startBtn.addEventListener('click', () => {
|
| 222 |
-
startBtn.style.display = 'none';
|
|
|
|
| 223 |
|
| 224 |
-
//
|
| 225 |
sounds.forEach(s => {
|
| 226 |
s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{});
|
| 227 |
});
|
| 228 |
|
| 229 |
-
// Nyalakan Kamera (Resolusi rendah 320x240 agar lancar)
|
| 230 |
const camera = new Camera(videoElement, {
|
| 231 |
onFrame: async () => {
|
| 232 |
await hands.send({image: videoElement});
|
| 233 |
},
|
| 234 |
-
width:
|
| 235 |
-
height:
|
| 236 |
});
|
| 237 |
camera.start();
|
| 238 |
});
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Hand Pose Classifier - Buatan Zero Team</title>
|
| 7 |
|
| 8 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script>
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script>
|
| 10 |
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script>
|
| 11 |
|
| 12 |
<style>
|
| 13 |
+
/* Tampilan Background Premium Dark Mode */
|
| 14 |
body {
|
| 15 |
+
background: radial-gradient(circle at top, #1e293b, #0f172a);
|
| 16 |
+
color: #f8fafc;
|
| 17 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 18 |
display: flex;
|
| 19 |
flex-direction: column;
|
| 20 |
align-items: center;
|
| 21 |
+
margin: 0;
|
| 22 |
+
padding: 20px;
|
| 23 |
+
min-height: 100vh;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
}
|
| 25 |
+
|
| 26 |
+
h2 { margin-bottom: 5px; color: #38bdf8; text-shadow: 0 0 10px rgba(56, 189, 248, 0.5); }
|
| 27 |
+
p { color: #94a3b8; margin-top: 0; }
|
| 28 |
+
|
| 29 |
+
/* Desain Tombol Play Cantik (Gradient & Glow) */
|
| 30 |
+
#startBtn {
|
| 31 |
+
background: linear-gradient(135deg, #ec4899, #8b5cf6);
|
| 32 |
color: white;
|
| 33 |
border: none;
|
| 34 |
+
padding: 15px 35px;
|
| 35 |
+
font-size: 18px;
|
| 36 |
+
border-radius: 50px;
|
| 37 |
cursor: pointer;
|
|
|
|
| 38 |
font-weight: bold;
|
| 39 |
+
box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
|
| 40 |
+
transition: all 0.3s ease;
|
| 41 |
+
margin: 20px 0;
|
| 42 |
+
letter-spacing: 1px;
|
| 43 |
+
text-transform: uppercase;
|
| 44 |
+
}
|
| 45 |
+
#startBtn:hover {
|
| 46 |
+
transform: translateY(-3px);
|
| 47 |
+
box-shadow: 0 8px 25px rgba(236, 72, 153, 0.6);
|
| 48 |
+
background: linear-gradient(135deg, #f472b6, #a78bfa);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
/* Label Status yang Responsif */
|
| 52 |
+
#statusContainer {
|
| 53 |
+
background: rgba(15, 23, 42, 0.8);
|
| 54 |
+
border: 1px solid #334155;
|
| 55 |
+
padding: 15px 30px;
|
| 56 |
+
border-radius: 12px;
|
| 57 |
+
margin-bottom: 20px;
|
| 58 |
+
min-width: 300px;
|
| 59 |
+
text-align: center;
|
| 60 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.3);
|
| 61 |
}
|
|
|
|
| 62 |
#statusPose {
|
| 63 |
+
font-size: 24px;
|
| 64 |
font-weight: bold;
|
| 65 |
+
color: #10b981; /* Warna hijau default */
|
| 66 |
+
transition: color 0.3s;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/* Layar Kamera Diperbesar */
|
| 70 |
+
.monitor-container { position: relative; }
|
| 71 |
+
canvas {
|
| 72 |
+
border: 3px solid #3b82f6;
|
| 73 |
+
box-shadow: 0 0 25px rgba(59, 130, 246, 0.5);
|
| 74 |
+
border-radius: 16px;
|
| 75 |
+
background-color: #000;
|
| 76 |
+
width: 640px; /* Layar Lebih Besar */
|
| 77 |
+
height: 480px; /* Proporsional 4:3 */
|
| 78 |
+
max-width: 90vw; /* Responsif di layar kecil */
|
| 79 |
+
object-fit: cover;
|
| 80 |
}
|
| 81 |
</style>
|
| 82 |
</head>
|
| 83 |
<body>
|
| 84 |
|
| 85 |
+
<h2>🤖 AI Vision: Hand Gestures</h2>
|
| 86 |
+
<p>Sistem Klasifikasi 5 Pola Jari Secara Real-Time</p>
|
| 87 |
|
| 88 |
+
<button id="startBtn">▶ Mulai Sistem Deteksi</button>
|
| 89 |
|
| 90 |
+
<div id="statusContainer">
|
| 91 |
+
<div id="statusPose" style="color: #94a3b8;">Menunggu Kamera...</div>
|
| 92 |
+
</div>
|
| 93 |
|
| 94 |
<div class="monitor-container">
|
| 95 |
<video id="videoElement" style="display: none;" autoplay playsinline></video>
|
| 96 |
+
<canvas id="outputCanvas" width="640" height="480"></canvas>
|
|
|
|
| 97 |
</div>
|
| 98 |
|
| 99 |
+
<audio id="audio1" src="suara1.mp3"></audio>
|
| 100 |
+
<audio id="audio2" src="suara2.mp3"></audio>
|
| 101 |
+
<audio id="audio3" src="suara3.mp3"></audio>
|
| 102 |
+
<audio id="audio4" src="suara4.mp3"></audio>
|
| 103 |
+
<audio id="audio5" src="suara5.mp3"></audio>
|
| 104 |
+
|
| 105 |
+
<script>
|
| 106 |
const videoElement = document.getElementById('videoElement');
|
| 107 |
const canvasElement = document.getElementById('outputCanvas');
|
| 108 |
const canvasCtx = canvasElement.getContext('2d');
|
|
|
|
| 109 |
const startBtn = document.getElementById('startBtn');
|
| 110 |
const statusPose = document.getElementById('statusPose');
|
| 111 |
|
|
|
|
| 112 |
const sounds = [
|
| 113 |
document.getElementById('audio1'),
|
| 114 |
document.getElementById('audio2'),
|
|
|
|
| 117 |
document.getElementById('audio5')
|
| 118 |
];
|
| 119 |
|
| 120 |
+
let currentActivePoseId = null; // Menyimpan ID pose yang sedang aktif
|
|
|
|
| 121 |
|
| 122 |
+
// Fungsi Matematika Jarak (Akurasi Tinggi)
|
|
|
|
| 123 |
function getDistance(p1, p2) {
|
| 124 |
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
| 125 |
}
|
| 126 |
|
| 127 |
+
// Logika Klasifikasi 5 Pose
|
| 128 |
function classifyPose(landmarks) {
|
| 129 |
+
// Cek jari terbuka (ujung jari lebih tinggi dari pangkal sendi)
|
| 130 |
+
const indexOpen = landmarks[8].y < landmarks[6].y;
|
| 131 |
+
const middleOpen = landmarks[12].y < landmarks[10].y;
|
| 132 |
+
const ringOpen = landmarks[16].y < landmarks[14].y;
|
| 133 |
+
const pinkyOpen = landmarks[20].y < landmarks[18].y;
|
| 134 |
|
| 135 |
+
// Jarak jempol ke pangkal telunjuk (untuk mendeteksi jempol terbuka/tertutup)
|
| 136 |
+
const thumbOpen = getDistance(landmarks[4], landmarks[5]) > 0.08;
|
| 137 |
+
|
| 138 |
+
// 5. KEPALAN TANGAN (FIST) - 4 jari utama tertutup rapat
|
| 139 |
+
if (!indexOpen && !middleOpen && !ringOpen && !pinkyOpen) {
|
| 140 |
+
return { id: 5, name: "✊ Kepalan Tangan", color: "#ef4444" }; // Merah
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
}
|
| 142 |
|
| 143 |
+
// 4. TELAPAK TERBUKA (OPEN PALM) - Semua jari terbuka
|
| 144 |
+
if (indexOpen && middleOpen && ringOpen && pinkyOpen && thumbOpen) {
|
| 145 |
+
return { id: 4, name: "🖐️ Telapak Terbuka", color: "#3b82f6" }; // Biru
|
| 146 |
}
|
| 147 |
|
| 148 |
+
// 2. VICTORY / PEACE - Telunjuk & Tengah terbuka, sisanya tertutup
|
| 149 |
+
if (indexOpen && middleOpen && !ringOpen && !pinkyOpen) {
|
| 150 |
+
return { id: 2, name: "✌️ Victory / Peace", color: "#a855f7" }; // Ungu
|
| 151 |
}
|
| 152 |
|
| 153 |
+
// 1. THUMBS UP (JEMPOL) - Hanya jempol yang terbuka lebar
|
| 154 |
+
if (thumbOpen && !indexOpen && !middleOpen && !ringOpen && !pinkyOpen) {
|
| 155 |
+
return { id: 1, name: "👍 Thumbs Up", color: "#eab308" }; // Kuning
|
| 156 |
}
|
| 157 |
|
| 158 |
+
// 3. OKAY SIGN - Ujung telunjuk & jempol bersentuhan, 3 jari lain terbuka
|
| 159 |
+
const thumbIndexTipDist = getDistance(landmarks[4], landmarks[8]);
|
| 160 |
+
if (thumbIndexTipDist < 0.05 && middleOpen && ringOpen && pinkyOpen) {
|
| 161 |
+
return { id: 3, name: "👌 Tanda Okay", color: "#10b981" }; // Hijau
|
| 162 |
}
|
| 163 |
|
| 164 |
+
return null; // Jika tangan berantakan / tidak membentuk pola
|
| 165 |
}
|
| 166 |
|
| 167 |
+
// Konfigurasi MediaPipe (Kecepatan & Akurasi)
|
| 168 |
const hands = new Hands({locateFile: (file) => {
|
| 169 |
return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`;
|
| 170 |
}});
|
| 171 |
|
| 172 |
hands.setOptions({
|
| 173 |
+
maxNumHands: 1,
|
| 174 |
+
modelComplexity: 1, // Ditingkatkan sedikit agar lebih presisi membaca jari
|
| 175 |
+
minDetectionConfidence: 0.7,
|
| 176 |
+
minTrackingConfidence: 0.7
|
| 177 |
});
|
| 178 |
|
|
|
|
| 179 |
hands.onResults((results) => {
|
|
|
|
| 180 |
canvasCtx.save();
|
| 181 |
canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 182 |
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height);
|
|
|
|
| 185 |
|
| 186 |
if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) {
|
| 187 |
for (const landmarks of results.multiHandLandmarks) {
|
| 188 |
+
// Gambar kerangka (Warna Neon)
|
| 189 |
+
drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: '#ec4899', lineWidth: 4});
|
| 190 |
+
drawLandmarks(canvasCtx, landmarks, {color: '#ffffff', lineWidth: 2, radius: 3});
|
| 191 |
|
|
|
|
| 192 |
detectedPose = classifyPose(landmarks);
|
| 193 |
}
|
| 194 |
}
|
| 195 |
canvasCtx.restore();
|
| 196 |
|
| 197 |
+
// --- LOGIKA RESPONSIF (AUDIO & TEKS) ---
|
|
|
|
|
|
|
| 198 |
if (detectedPose) {
|
| 199 |
+
// Tangan terdeteksi pola tertentu
|
| 200 |
+
statusPose.textContent = detectedPose.name;
|
| 201 |
+
statusPose.style.color = detectedPose.color;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
+
// Jika pola BERUBAH dari pola sebelumnya, mainkan suara baru!
|
| 204 |
+
if (currentActivePoseId !== detectedPose.id) {
|
| 205 |
+
currentActivePoseId = detectedPose.id;
|
| 206 |
+
|
| 207 |
+
// Matikan semua suara yang sedang berjalan
|
| 208 |
+
sounds.forEach(s => { s.pause(); s.currentTime = 0; });
|
| 209 |
+
|
| 210 |
+
// Putar suara yang sesuai
|
| 211 |
const soundToPlay = sounds[detectedPose.id - 1];
|
| 212 |
+
if (soundToPlay) soundToPlay.play();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
}
|
| 214 |
+
|
| 215 |
} else {
|
| 216 |
+
// Tangan hilang dari kamera ATAU tidak membentuk 5 pola tersebut
|
| 217 |
+
if (currentActivePoseId !== null) {
|
| 218 |
+
statusPose.textContent = "Menunggu formasi jari...";
|
| 219 |
+
statusPose.style.color = "#94a3b8";
|
| 220 |
+
currentActivePoseId = null; // Reset status
|
| 221 |
+
}
|
| 222 |
}
|
| 223 |
});
|
| 224 |
|
| 225 |
+
// Event Tombol Play
|
| 226 |
startBtn.addEventListener('click', () => {
|
| 227 |
+
startBtn.style.display = 'none';
|
| 228 |
+
statusPose.textContent = "Menyiapkan Kamera...";
|
| 229 |
|
| 230 |
+
// Buka blokir audio browser
|
| 231 |
sounds.forEach(s => {
|
| 232 |
s.play().then(() => { s.pause(); s.currentTime = 0; }).catch(()=>{});
|
| 233 |
});
|
| 234 |
|
|
|
|
| 235 |
const camera = new Camera(videoElement, {
|
| 236 |
onFrame: async () => {
|
| 237 |
await hands.send({image: videoElement});
|
| 238 |
},
|
| 239 |
+
width: 640,
|
| 240 |
+
height: 480
|
| 241 |
});
|
| 242 |
camera.start();
|
| 243 |
});
|