Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +90 -151
templates/index.html
CHANGED
@@ -3,187 +3,126 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title
|
7 |
-
<link href="https://fonts.googleapis.com/css2?family=
|
8 |
<style>
|
9 |
body {
|
10 |
-
font-family: '
|
11 |
-
background: linear-gradient(135deg, #
|
12 |
margin: 0;
|
|
|
13 |
display: flex;
|
14 |
justify-content: center;
|
15 |
align-items: center;
|
16 |
height: 100vh;
|
17 |
-
|
18 |
}
|
19 |
.container {
|
20 |
-
background:
|
21 |
-
padding:
|
22 |
-
border-radius:
|
23 |
-
width: 400px;
|
24 |
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
|
25 |
}
|
26 |
h1 {
|
27 |
-
font-size:
|
28 |
-
|
29 |
-
|
30 |
}
|
31 |
-
|
32 |
-
font-size:
|
33 |
-
margin-
|
34 |
-
display: block;
|
35 |
-
text-align: left;
|
36 |
}
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
45 |
}
|
46 |
-
.
|
47 |
-
|
48 |
-
font-size: 16px;
|
49 |
-
color: #ff6a00;
|
50 |
-
font-weight: bold;
|
51 |
}
|
52 |
.status {
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
57 |
</style>
|
58 |
</head>
|
59 |
<body>
|
60 |
<div class="container">
|
61 |
-
<h1>Welcome to Biryani Hub
|
|
|
62 |
|
63 |
-
|
64 |
-
<input type="text" id="name" placeholder="Your
|
|
|
65 |
|
66 |
-
|
67 |
-
<
|
68 |
|
69 |
-
|
70 |
-
<p class="status" id="status">
|
71 |
</div>
|
72 |
|
73 |
<script>
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
if ('webkitSpeechRecognition' in window) {
|
81 |
-
recognition = new webkitSpeechRecognition();
|
82 |
-
recognition.continuous = false;
|
83 |
-
recognition.interimResults = false;
|
84 |
-
recognition.lang = 'en-US';
|
85 |
-
} else {
|
86 |
-
alert("Speech Recognition API is not supported in this browser.");
|
87 |
-
}
|
88 |
-
|
89 |
-
function speak(text, callback) {
|
90 |
-
const speech = new SpeechSynthesisUtterance(text);
|
91 |
-
speech.onend = callback;
|
92 |
-
window.speechSynthesis.speak(speech);
|
93 |
-
}
|
94 |
-
|
95 |
-
function startListeningForName() {
|
96 |
-
const status = document.getElementById('status');
|
97 |
-
const nameInput = document.getElementById('name');
|
98 |
-
status.textContent = "Listening for your name...";
|
99 |
-
recognition.start();
|
100 |
-
|
101 |
-
recognition.onresult = function(event) {
|
102 |
-
let transcript = event.results[0][0].transcript.trim().toUpperCase().replace(/\s+/g, "");
|
103 |
-
|
104 |
-
if (transcript === "NEXT") {
|
105 |
-
recognition.stop();
|
106 |
-
isCapturingName = false;
|
107 |
-
isCapturingEmail = true;
|
108 |
-
status.textContent = "Your name is: " + currentName;
|
109 |
-
|
110 |
-
speak("Your name is " + currentName + ". If correct, say 'confirm'. If wrong, say 'edit'.", function() {
|
111 |
-
recognition.start();
|
112 |
-
recognition.onresult = function(event) {
|
113 |
-
let confirmTranscript = event.results[0][0].transcript.trim().toLowerCase();
|
114 |
-
if (confirmTranscript === "confirm") {
|
115 |
-
speak("Now, please tell me your email, letter by letter", startListeningForEmail);
|
116 |
-
} else if (confirmTranscript === "edit") {
|
117 |
-
currentName = "";
|
118 |
-
nameInput.value = "";
|
119 |
-
speak("Tell your name again.", startListeningForName);
|
120 |
-
}
|
121 |
-
};
|
122 |
-
});
|
123 |
-
|
124 |
-
return;
|
125 |
-
}
|
126 |
-
|
127 |
-
currentName += transcript;
|
128 |
-
nameInput.value = currentName;
|
129 |
-
};
|
130 |
-
}
|
131 |
-
|
132 |
-
function startListeningForEmail() {
|
133 |
-
const status = document.getElementById('status');
|
134 |
-
const emailInput = document.getElementById('email');
|
135 |
-
|
136 |
-
recognition = new webkitSpeechRecognition();
|
137 |
-
recognition.continuous = false;
|
138 |
-
recognition.interimResults = false;
|
139 |
-
recognition.lang = 'en-US';
|
140 |
-
|
141 |
-
status.textContent = "Listening for your email...";
|
142 |
-
recognition.start();
|
143 |
-
|
144 |
-
recognition.onresult = function(event) {
|
145 |
-
let transcript = event.results[0][0].transcript.trim().toUpperCase().replace(/\s+/g, "");
|
146 |
-
|
147 |
-
transcript = transcript.replace(/\bAT\b/g, "@").replace(/\bDOT\b/g, ".");
|
148 |
-
|
149 |
-
if (transcript === "NEXT") {
|
150 |
-
recognition.stop();
|
151 |
-
isCapturingEmail = false;
|
152 |
-
status.textContent = "Your email is: " + currentEmail;
|
153 |
-
|
154 |
-
speak("Your email is " + currentEmail + ". If correct, say 'confirm'. If wrong, say 'edit'.", function() {
|
155 |
-
recognition.start();
|
156 |
-
recognition.onresult = function(event) {
|
157 |
-
let confirmTranscript = event.results[0][0].transcript.trim().toLowerCase();
|
158 |
-
if (confirmTranscript === "confirm") {
|
159 |
-
speak("Registration complete. Thank you!", function() {
|
160 |
-
setTimeout(() => location.reload(), 10000);
|
161 |
-
});
|
162 |
-
} else if (confirmTranscript === "edit") {
|
163 |
-
currentEmail = "";
|
164 |
-
emailInput.value = "";
|
165 |
-
speak("Tell your email again.", startListeningForEmail);
|
166 |
-
}
|
167 |
-
};
|
168 |
-
});
|
169 |
-
|
170 |
-
return;
|
171 |
-
}
|
172 |
-
|
173 |
-
currentEmail += transcript;
|
174 |
-
emailInput.value = currentEmail;
|
175 |
-
};
|
176 |
-
}
|
177 |
-
|
178 |
-
function startProcess() {
|
179 |
-
speak("Welcome to Biryani Hub", function() {
|
180 |
-
speak("Tell me your name, letter by letter, and say 'next' when you're done", startListeningForName);
|
181 |
});
|
|
|
182 |
}
|
183 |
|
184 |
-
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
</script>
|
188 |
</body>
|
189 |
-
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>🍛 Biryani Hub - Voice Registration</title>
|
7 |
+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
|
8 |
<style>
|
9 |
body {
|
10 |
+
font-family: 'Poppins', sans-serif;
|
11 |
+
background: linear-gradient(135deg, #ff6f61, #ffcc00);
|
12 |
margin: 0;
|
13 |
+
padding: 0;
|
14 |
display: flex;
|
15 |
justify-content: center;
|
16 |
align-items: center;
|
17 |
height: 100vh;
|
18 |
+
color: #333;
|
19 |
}
|
20 |
.container {
|
21 |
+
background: rgba(255, 255, 255, 0.9);
|
22 |
+
padding: 2rem;
|
23 |
+
border-radius: 15px;
|
|
|
24 |
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
25 |
+
text-align: center;
|
26 |
+
max-width: 500px;
|
27 |
+
width: 100%;
|
28 |
}
|
29 |
h1 {
|
30 |
+
font-size: 2.5rem;
|
31 |
+
color: #ff6f61;
|
32 |
+
margin-bottom: 1rem;
|
33 |
}
|
34 |
+
p {
|
35 |
+
font-size: 1.1rem;
|
36 |
+
margin-bottom: 2rem;
|
|
|
|
|
37 |
}
|
38 |
+
.btn {
|
39 |
+
background: #ff6f61;
|
40 |
+
color: white;
|
41 |
+
border: none;
|
42 |
+
padding: 0.8rem 2rem;
|
43 |
+
font-size: 1rem;
|
44 |
+
border-radius: 25px;
|
45 |
+
cursor: pointer;
|
46 |
+
transition: background 0.3s ease;
|
47 |
}
|
48 |
+
.btn:hover {
|
49 |
+
background: #ff4a3d;
|
|
|
|
|
|
|
50 |
}
|
51 |
.status {
|
52 |
+
margin-top: 1.5rem;
|
53 |
+
font-size: 0.9rem;
|
54 |
+
color: #666;
|
55 |
+
}
|
56 |
+
.input-field {
|
57 |
+
margin: 1rem 0;
|
58 |
+
padding: 0.8rem;
|
59 |
+
width: 100%;
|
60 |
+
border: 1px solid #ddd;
|
61 |
+
border-radius: 5px;
|
62 |
+
font-size: 1rem;
|
63 |
}
|
64 |
</style>
|
65 |
</head>
|
66 |
<body>
|
67 |
<div class="container">
|
68 |
+
<h1>Welcome to Biryani Hub 🍛</h1>
|
69 |
+
<p>Register using your voice! Click below to start.</p>
|
70 |
|
71 |
+
<!-- Input Fields -->
|
72 |
+
<input type="text" id="name" class="input-field" placeholder="Your Name" readonly>
|
73 |
+
<input type="text" id="email" class="input-field" placeholder="Your Email" readonly>
|
74 |
|
75 |
+
<!-- Action Button -->
|
76 |
+
<button class="btn" id="startBtn">Start Voice Registration</button>
|
77 |
|
78 |
+
<!-- Status Message -->
|
79 |
+
<p class="status" id="status">Press the button and speak clearly.</p>
|
80 |
</div>
|
81 |
|
82 |
<script>
|
83 |
+
// Hugging Face ASR Integration
|
84 |
+
async function transcribeSpeech(audioBlob) {
|
85 |
+
const response = await fetch("https://api-inference.huggingface.co/models/openai/whisper-small", {
|
86 |
+
headers: { Authorization: "Bearer YOUR_HF_TOKEN" },
|
87 |
+
method: "POST",
|
88 |
+
body: audioBlob,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
});
|
90 |
+
return await response.json();
|
91 |
}
|
92 |
|
93 |
+
// Voice Registration Logic
|
94 |
+
let isProcessing = false;
|
95 |
+
const startBtn = document.getElementById('startBtn');
|
96 |
+
const status = document.getElementById('status');
|
97 |
+
const nameInput = document.getElementById('name');
|
98 |
+
const emailInput = document.getElementById('email');
|
99 |
+
|
100 |
+
startBtn.addEventListener('click', async () => {
|
101 |
+
if (isProcessing) return;
|
102 |
+
isProcessing = true;
|
103 |
+
status.textContent = "Listening... Speak your name letter by letter.";
|
104 |
+
|
105 |
+
try {
|
106 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
107 |
+
const mediaRecorder = new MediaRecorder(stream);
|
108 |
+
let audioChunks = [];
|
109 |
+
|
110 |
+
mediaRecorder.ondataavailable = (e) => audioChunks.push(e.data);
|
111 |
+
mediaRecorder.onstop = async () => {
|
112 |
+
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
113 |
+
const transcription = await transcribeSpeech(audioBlob);
|
114 |
+
nameInput.value = transcription.text.toUpperCase();
|
115 |
+
status.textContent = "Name captured! Now speak your email.";
|
116 |
+
};
|
117 |
+
|
118 |
+
mediaRecorder.start();
|
119 |
+
setTimeout(() => mediaRecorder.stop(), 5000); // Record for 5 seconds
|
120 |
+
} catch (error) {
|
121 |
+
status.textContent = "Error: Microphone access denied.";
|
122 |
+
} finally {
|
123 |
+
isProcessing = false;
|
124 |
+
}
|
125 |
+
});
|
126 |
</script>
|
127 |
</body>
|
128 |
+
</html>
|