-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA22.html
More file actions
91 lines (76 loc) · 3.05 KB
/
A22.html
File metadata and controls
91 lines (76 loc) · 3.05 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
<!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.4s ease;
}
@keyframes slideIn {
from { transform: translateY(-20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
</style>
</head>
<body class="bg-black text-white flex items-center justify-center min-h-screen px-4">
<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"></div>
<div id="emotion" class="text-sm mt-2 text-green-400"></div>
</div>
<!-- Toast container -->
<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");
function showToast(message) {
toast.textContent = message;
toast.classList.remove("hidden");
setTimeout(() => {
toast.classList.add("hidden");
}, 3000);
}
let recognition;
if ('webkitSpeechRecognition' in window) {
recognition = new webkitSpeechRecognition();
} else {
showToast("Speech recognition not supported in this browser.");
}
startBtn.onclick = () => {
result.textContent = "Listening...";
emotion.textContent = "";
recognition.continuous = false;
recognition.interimResults = false;
recognition.lang = 'en-US';
const startTime = performance.now();
recognition.start();
recognition.onresult = (e) => {
const endTime = performance.now();
const spoken = e.results[0][0].transcript;
const duration = (endTime - startTime) / 1000;
const confidence = e.results[0][0].confidence;
result.textContent = `"${spoken}"`;
let isHuman = spoken.toLowerCase().includes("i am not a robot") && duration > 1.5;
let emotionHint = (duration < 1.5 || confidence < 0.8) ? "Flat tone" : "Emotional tone";
emotion.textContent = isHuman ?
`✅ Detected as Human Voice (${emotionHint})` :
`⚠️ Possibly AI Voice (${emotionHint})`;
};
recognition.onerror = (e) => {
showToast("Error: " + e.error);
result.textContent = "";
emotion.textContent = "";
};
};
</script>
</body>
</html>