lokesh341 commited on
Commit
7c86366
·
verified ·
1 Parent(s): d9ec8d8

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +35 -45
templates/index.html CHANGED
@@ -8,7 +8,7 @@
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;
@@ -26,7 +26,7 @@
26
  h1 {
27
  font-size: 30px;
28
  font-weight: bold;
29
- color: #ff6a00; /* Bright orange for title */
30
  }
31
  label {
32
  font-size: 18px;
@@ -59,30 +59,24 @@
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 currentName = ""; // Variable to store the name as it's being formed
80
- let isNameCaptured = false;
81
- let isEmailCaptured = false;
82
 
83
  if ('webkitSpeechRecognition' in window) {
84
  recognition = new webkitSpeechRecognition();
85
- recognition.continuous = true; // Keep listening
86
  recognition.interimResults = false;
87
  recognition.lang = 'en-US';
88
  } else {
@@ -91,66 +85,62 @@
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
-
106
- // Capture the individual letter spoken
107
- currentName += transcript; // Append the current letter to the name
108
- nameInput.value = currentName; // Display the updated name input
 
109
 
110
- // Optionally, speak out the name as it's being typed
111
- speak(transcript, null); // Say the captured letter
112
-
113
- // If a space or "next" word is detected, stop and move to email
114
- if (transcript.toLowerCase() === "next") {
115
  recognition.stop();
116
- isNameCaptured = true;
117
- status.textContent = "Listening for your email...";
118
- speak("Tell me your email", startListeningForEmail);
119
- }
120
- };
 
 
121
  }
122
 
123
  function startListeningForEmail() {
124
  const status = document.getElementById('status');
125
- const emailInput = document.getElementById('email');
126
  status.textContent = "Listening for your email...";
127
  recognition.start();
128
- recognition.onresult = function(event) {
129
- let transcript = event.results[0][0].transcript.trim();
130
-
131
- // Replace "at" with "@" for email
132
- transcript = transcript.replace(/\bat\b/g, '@').trim();
133
-
134
- // Clean any spaces around the email
135
- const cleanedEmail = transcript.replace(/\s+/g, '');
136
 
137
- emailInput.value = cleanedEmail; // Set the email field with cleaned input
 
 
 
138
  status.textContent = 'Registration complete.';
 
139
 
140
- // After registration, refresh the page after 20 seconds
141
- setTimeout(() => location.reload(), 20000); // Refresh after 20 seconds
142
- isEmailCaptured = true; // Mark email as captured
143
  };
144
  }
145
 
146
  function startProcess() {
147
  speak("Welcome to Biryani Hub", function() {
148
- speak("Tell me your name, letter by letter, and say 'next' when you're done", startListeningForName);
149
  });
150
  }
151
 
152
  window.onload = function () {
153
- setTimeout(startProcess, 4000); // Start process after 4 seconds
154
  };
155
  </script>
156
  </body>
 
8
  <style>
9
  body {
10
  font-family: 'Roboto', sans-serif;
11
+ background: linear-gradient(135deg, #f4c542, #ff8f6a);
12
  margin: 0;
13
  display: flex;
14
  justify-content: center;
 
26
  h1 {
27
  font-size: 30px;
28
  font-weight: bold;
29
+ color: #ff6a00;
30
  }
31
  label {
32
  font-size: 18px;
 
59
  <div class="container">
60
  <h1>Welcome to Biryani Hub</h1>
61
 
 
62
  <label for="name">Your Name</label>
63
  <input type="text" id="name" placeholder="Your name will appear here..." readonly>
64
+
 
65
  <label for="email">Your Email</label>
66
  <input type="text" id="email" placeholder="Your email will appear here..." readonly>
67
+
 
68
  <p class="info" id="infoMessage">Listening will start automatically...</p>
 
 
69
  <p class="status" id="status">Initializing...</p>
70
  </div>
71
 
72
  <script>
73
  let recognition;
74
+ let nameCaptured = "";
75
+ let emailCaptured = "";
 
76
 
77
  if ('webkitSpeechRecognition' in window) {
78
  recognition = new webkitSpeechRecognition();
79
+ recognition.continuous = false;
80
  recognition.interimResults = false;
81
  recognition.lang = 'en-US';
82
  } else {
 
85
 
86
  function speak(text, callback) {
87
  const speech = new SpeechSynthesisUtterance(text);
88
+ speech.onend = callback;
89
  window.speechSynthesis.speak(speech);
90
  }
91
 
92
  function startListeningForName() {
93
  const status = document.getElementById('status');
 
94
  status.textContent = "Listening for your name...";
95
  recognition.start();
96
+
97
  recognition.onresult = function(event) {
98
+ nameCaptured = event.results[0][0].transcript.trim();
99
+ document.getElementById('name').value = nameCaptured;
100
+ recognition.stop();
101
+ confirmName();
102
+ };
103
+ }
104
 
105
+ function confirmName() {
106
+ speak("You said " + nameCaptured + ". Is it okay, or do you want to change it?", function() {
107
+ recognition.start();
108
+ recognition.onresult = function(event) {
109
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
110
  recognition.stop();
111
+ if (confirmation === "ok" || confirmation === "okay" || confirmation === "yes") {
112
+ speak("Great! Now, tell me your email.", startListeningForEmail);
113
+ } else {
114
+ speak("Let's try again. Tell me your name.", startListeningForName);
115
+ }
116
+ };
117
+ });
118
  }
119
 
120
  function startListeningForEmail() {
121
  const status = document.getElementById('status');
 
122
  status.textContent = "Listening for your email...";
123
  recognition.start();
 
 
 
 
 
 
 
 
124
 
125
+ recognition.onresult = function(event) {
126
+ emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
127
+ document.getElementById('email').value = emailCaptured;
128
+ recognition.stop();
129
  status.textContent = 'Registration complete.';
130
+ speak("Your registration is complete. Thank you for registering.");
131
 
132
+ setTimeout(() => location.reload(), 20000);
 
 
133
  };
134
  }
135
 
136
  function startProcess() {
137
  speak("Welcome to Biryani Hub", function() {
138
+ speak("Tell me your name, and I will confirm it with you.", startListeningForName);
139
  });
140
  }
141
 
142
  window.onload = function () {
143
+ setTimeout(startProcess, 4000);
144
  };
145
  </script>
146
  </body>