-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA69.html
More file actions
177 lines (146 loc) · 6.03 KB
/
A69.html
File metadata and controls
177 lines (146 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Human Voice Detector</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Viga&display=swap" rel="stylesheet">
<style>
body { font-family: 'Viga', sans-serif; }
.toast { animation: slideIn 0.3s ease; }
@keyframes slideIn {
from { transform: translateY(-20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
</style>
</head>
<body class="bg-black text-white flex flex-col items-center justify-center min-h-screen px-4 relative">
<div id="cooldownTimer" class="absolute top-4 text-red-400 font-semibold hidden"></div>
<div class="w-full max-w-md p-6 bg-zinc-900 rounded-2xl shadow-2xl text-center space-y-4 border border-gray-700">
<h1 class="text-2xl font-bold text-yellow-400">Human Voice Detector</h1>
<p class="text-sm text-gray-400">Say: "I am not a robot"</p>
<button id="startBtn" class="bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded-xl transition-all">Start Recording</button>
<div id="result" class="text-lg font-medium mt-4 text-white"></div>
<div id="emotion" class="text-sm mt-2 text-green-400"></div>
</div>
<!-- Toast -->
<div id="toast" class="hidden fixed top-5 right-5 bg-red-600 text-white px-4 py-2 rounded-xl shadow-lg toast z-50"></div>
<script>
const startBtn = document.getElementById("startBtn");
const result = document.getElementById("result");
const emotion = document.getElementById("emotion");
const toast = document.getElementById("toast");
const cooldownTimer = document.getElementById("cooldownTimer");
let recognition;
let attempts = parseInt(localStorage.getItem("attempts") || "0");
const cooldownKey = "voiceCooldown";
const maxAttempts = 3;
const cooldownMinutes = 10;
if ('webkitSpeechRecognition' in window) {
recognition = new webkitSpeechRecognition();
} else {
showToast("Speech recognition not supported.");
}
function showToast(message) {
toast.textContent = message;
toast.classList.remove("hidden");
setTimeout(() => toast.classList.add("hidden"), 3000);
}
function updateCooldownTimer() {
const stored = localStorage.getItem(cooldownKey);
if (!stored) return cooldownTimer.classList.add("hidden");
const expires = new Date(stored);
const now = new Date();
const diff = Math.floor((expires - now) / 1000);
if (diff <= 0) {
localStorage.removeItem(cooldownKey);
localStorage.setItem("attempts", "0");
cooldownTimer.classList.add("hidden");
startBtn.disabled = false;
startBtn.textContent = "Start Recording";
return;
}
const minutes = Math.floor(diff / 60);
const seconds = diff % 60;
cooldownTimer.classList.remove("hidden");
cooldownTimer.textContent = `Cooldown: Try again in ${minutes}m ${seconds}s`;
setTimeout(updateCooldownTimer, 1000);
}
function startRecording() {
if (attempts >= maxAttempts) {
showToast("Limit reached. Try again after cooldown.");
return;
}
result.textContent = "";
emotion.textContent = "";
startBtn.disabled = true;
startBtn.textContent = "Listening...";
startBtn.classList.remove("bg-blue-600");
startBtn.classList.add("border", "border-blue-400", "bg-transparent");
recognition.lang = "en-US";
recognition.continuous = false;
recognition.interimResults = false;
const startTime = performance.now();
let spoken = "";
recognition.start();
recognition.onresult = (e) => {
const endTime = performance.now();
spoken = e.results[0][0].transcript.trim();
const confidence = e.results[0][0].confidence;
const duration = (endTime - startTime) / 1000;
result.textContent = `"${spoken}"`;
if (spoken.toLowerCase() === "i am not a robot" && duration > 1.5 && confidence > 0.6) {
emotion.textContent = `✅ Human Voice Detected (Confidence: ${Math.round(confidence * 100)}%)`;
startBtn.textContent = "Start Recording";
startBtn.disabled = false;
} else {
attempts++;
localStorage.setItem("attempts", attempts);
emotion.textContent = `⚠️ Not a valid human phrase or tone`;
if (attempts >= maxAttempts) {
const cooldownEnd = new Date();
cooldownEnd.setMinutes(cooldownEnd.getMinutes() + cooldownMinutes);
localStorage.setItem(cooldownKey, cooldownEnd.toISOString());
updateCooldownTimer();
} else {
startBtn.textContent = "Try Again";
startBtn.disabled = false;
}
}
startBtn.classList.remove("border", "bg-transparent");
startBtn.classList.add("bg-blue-600");
};
recognition.onerror = () => {
spoken = "";
result.textContent = "No speech detected.";
emotion.textContent = "⚠️ Detection failed.";
attempts++;
localStorage.setItem("attempts", attempts);
if (attempts >= maxAttempts) {
const cooldownEnd = new Date();
cooldownEnd.setMinutes(cooldownEnd.getMinutes() + cooldownMinutes);
localStorage.setItem(cooldownKey, cooldownEnd.toISOString());
updateCooldownTimer();
} else {
startBtn.textContent = "Try Again";
startBtn.disabled = false;
}
startBtn.classList.remove("border", "bg-transparent");
startBtn.classList.add("bg-blue-600");
};
}
startBtn.onclick = () => {
const cooldown = localStorage.getItem(cooldownKey);
if (cooldown && new Date(cooldown) > new Date()) {
updateCooldownTimer();
showToast("Cooldown active. Wait before trying again.");
return;
}
startRecording();
};
// Initialize cooldown timer if needed
updateCooldownTimer();
</script>
</body>
</html>