lokesh341 commited on
Commit
fe03a0b
·
verified ·
1 Parent(s): 6b18c62

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +110 -86
templates/index.html CHANGED
@@ -3,126 +3,150 @@
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>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Biryani Hub Registration</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
8
  <style>
9
  body {
10
+ font-family: 'Roboto', sans-serif;
11
+ background: linear-gradient(135deg, #f4c542, #ff8f6a); /* Light gradient background */
12
  margin: 0;
 
13
  display: flex;
14
  justify-content: center;
15
  align-items: center;
16
  height: 100vh;
17
+ text-align: center;
18
  }
19
  .container {
20
+ background: lightblue;
21
+ padding: 40px 50px;
22
+ border-radius: 10px;
23
+ width: 400px;
24
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
 
 
 
25
  }
26
  h1 {
27
+ font-size: 30px;
28
+ font-weight: bold;
29
+ color: #ff6a00; /* Bright orange for title */
30
  }
31
+ label {
32
+ font-size: 18px;
33
+ margin-top: 20px;
34
+ display: block;
35
+ text-align: left;
36
  }
37
+ input[type="text"] {
38
+ width: 100%;
39
+ padding: 10px;
40
+ font-size: 16px;
41
+ border: 1px solid #ccc;
42
+ border-radius: 5px;
43
+ margin-top: 8px;
 
 
44
  }
45
+ .info {
46
+ margin-top: 20px;
47
+ font-size: 16px;
48
+ color: #ff6a00;
49
+ font-weight: bold;
50
  }
51
  .status {
52
+ font-size: 14px;
53
+ color: gray;
54
+ margin-top: 20px;
 
 
 
 
 
 
 
 
55
  }
56
  </style>
57
  </head>
58
  <body>
59
  <div class="container">
60
+ <h1>Welcome to Biryani Hub</h1>
 
61
 
62
+ <!-- Name Input Field -->
63
+ <label for="name">Your Name</label>
64
+ <input type="text" id="name" placeholder="Your name will appear here..." readonly>
65
 
66
+ <!-- Email Input Field -->
67
+ <label for="email">Your Email</label>
68
+ <input type="text" id="email" placeholder="Your email will appear here..." readonly>
69
+
70
+ <!-- Info Message for Listening -->
71
+ <p class="info" id="infoMessage">Listening will start automatically...</p>
72
 
73
  <!-- Status Message -->
74
+ <p class="status" id="status">Initializing...</p>
75
  </div>
76
 
77
  <script>
78
+ let recognition;
79
+ let isListening = false;
80
+ let isNameCaptured = false;
81
+ let isEmailCaptured = false;
82
+
83
+ if ('webkitSpeechRecognition' in window) {
84
+ recognition = new webkitSpeechRecognition();
85
+ recognition.continuous = false; // Stop after capturing each input
86
+ recognition.interimResults = false;
87
+ recognition.lang = 'en-US';
88
+ } else {
89
+ alert("Speech Recognition API is not supported in this browser.");
90
  }
91
 
92
+ function speak(text, callback) {
93
+ const speech = new SpeechSynthesisUtterance(text);
94
+ speech.onend = callback; // Once the speech ends, call the next function
95
+ window.speechSynthesis.speak(speech);
96
+ }
 
97
 
98
+ function startListeningForName() {
99
+ const status = document.getElementById('status');
100
+ const nameInput = document.getElementById('name');
101
+ status.textContent = "Listening for your name...";
102
+ recognition.start();
103
+ recognition.onresult = function(event) {
104
+ const transcript = event.results[0][0].transcript.trim();
105
+ nameInput.value = transcript;
106
+ recognition.stop();
107
+ // Now, prompt for email
108
+ speak("Tell me your email", startListeningForEmail);
109
+ };
110
+ }
111
 
112
+ function startListeningForEmail() {
113
+ const status = document.getElementById('status');
114
+ const emailInput = document.getElementById('email');
115
+ status.textContent = "Listening for your email...";
116
+ recognition.start();
117
+ recognition.onresult = function(event) {
118
+ const transcript = event.results[0][0].transcript.trim();
119
+
120
+ // If name is captured, we now capture email
121
+ if (isNameCaptured && !isEmailCaptured) {
122
+ // Correct email input format by removing spaces and handling @ properly
123
+ const cleanedEmail = transcript.replace(/\s/g, '').replace(/\bat\b/g, '@'); // Replace "at" with "@"
124
+ emailInput.value = cleanedEmail; // Set the email field with cleaned input
125
+ status.textContent = 'Registration complete.';
126
+
127
+ // After registration, refresh the page after 20 seconds
128
+ setTimeout(() => location.reload(), 20000); // Refresh after 20 seconds
129
+ isEmailCaptured = true; // Mark email as captured
130
+ } else if (!isNameCaptured) {
131
+ // If name is not yet captured, capture name first
132
+ nameInput.value = transcript;
133
+ status.textContent = 'Listening for your email...'; // Prompt for email
134
+ recognition.stop(); // Stop listening for name
135
+ isNameCaptured = true; // Mark name as captured
136
+ recognition.start(); // Start listening for email
137
+ }
138
+ };
139
+ }
140
 
141
+ function startProcess() {
142
+ speak("Welcome to Biryani Hub", function() {
143
+ speak("Tell me your name", startListeningForName);
144
+ });
145
+ }
 
 
146
 
147
+ window.onload = function () {
148
+ setTimeout(startProcess, 4000); // Start process after 4 seconds
149
+ };
 
 
 
 
 
150
  </script>
151
  </body>
152
+ </html>