lokesh341 commited on
Commit
6bd41b6
·
verified ·
1 Parent(s): 3d12105

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +40 -40
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;
@@ -79,65 +79,65 @@
79
  let isListening = false;
80
  let isNameCaptured = false;
81
 
82
- // Initialize speech recognition
83
  if ('webkitSpeechRecognition' in window) {
84
  recognition = new webkitSpeechRecognition();
85
- recognition.continuous = true;
86
- recognition.interimResults = true;
87
  recognition.lang = 'en-US';
88
  } else {
89
  alert("Speech Recognition API is not supported in this browser.");
90
  }
91
 
92
- // Function to speak the welcome message automatically when the page loads
93
- function welcomeMessage() {
94
- const welcomeMsg = "Welcome to Biryani Hub. Please say your name after the beep.";
95
- const speech = new SpeechSynthesisUtterance(welcomeMsg);
96
  window.speechSynthesis.speak(speech);
97
  }
98
 
99
- // Function to start listening after the welcome message
100
- function startListening() {
101
  const status = document.getElementById('status');
102
  const nameInput = document.getElementById('name');
103
- const emailInput = document.getElementById('email');
104
 
105
- status.textContent = 'Listening for your name...';
106
- recognition.start(); // Start voice recognition
107
 
108
- // Handle recognition results
109
  recognition.onresult = function(event) {
110
- const transcript = event.results[event.resultIndex][0].transcript.trim();
111
- console.log('Recognized Text:', transcript); // Debugging line
112
- if (event.results[event.resultIndex].isFinal) {
113
- if (!isNameCaptured) {
114
- // If name is empty, fill it with the recognized text
115
- nameInput.value = transcript;
116
- status.textContent = 'Tell me your email...';
117
- isNameCaptured = true; // Mark name as captured
118
- recognition.stop(); // Stop listening for name
119
- recognition.start(); // Start listening for email
120
- } else if (isNameCaptured && !emailInput.value) {
121
- // If email is empty, fill it with the recognized text
122
- emailInput.value = transcript;
123
- status.textContent = 'Registration complete.';
124
-
125
- // After registration is complete, refresh page automatically after 15 seconds
126
- setTimeout(() => location.reload(), 15000); // Refresh after 15 seconds
127
- }
128
- }
129
  };
 
 
 
 
 
130
 
131
- recognition.onerror = function(event) {
132
- console.error('Speech recognition error:', event.error);
133
- status.textContent = 'Error recognizing speech. Please try again.';
 
 
 
 
 
 
 
 
 
134
  };
135
  }
136
 
137
- // Start the process when the page is loaded
 
 
 
 
 
138
  window.onload = function () {
139
- welcomeMessage(); // Automatically say the welcome message
140
- setTimeout(startListening, 5000); // Start listening after the welcome message
141
  };
142
  </script>
143
  </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;
 
79
  let isListening = false;
80
  let isNameCaptured = false;
81
 
 
82
  if ('webkitSpeechRecognition' in window) {
83
  recognition = new webkitSpeechRecognition();
84
+ recognition.continuous = false; // Stop after capturing each input
85
+ recognition.interimResults = false;
86
  recognition.lang = 'en-US';
87
  } else {
88
  alert("Speech Recognition API is not supported in this browser.");
89
  }
90
 
91
+ function speak(text, callback) {
92
+ const speech = new SpeechSynthesisUtterance(text);
93
+ speech.onend = callback; // Once the speech ends, call the next function
 
94
  window.speechSynthesis.speak(speech);
95
  }
96
 
97
+ function startListeningForName() {
 
98
  const status = document.getElementById('status');
99
  const nameInput = document.getElementById('name');
 
100
 
101
+ status.textContent = "Listening for your name...";
102
+ recognition.start();
103
 
 
104
  recognition.onresult = function(event) {
105
+ const transcript = event.results[0][0].transcript.trim();
106
+ nameInput.value = transcript;
107
+ recognition.stop();
108
+
109
+ // Now, prompt for email
110
+ speak("Tell me your email", startListeningForEmail);
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  };
112
+ }
113
+
114
+ function startListeningForEmail() {
115
+ const status = document.getElementById('status');
116
+ const emailInput = document.getElementById('email');
117
 
118
+ status.textContent = "Listening for your email...";
119
+ recognition.start();
120
+
121
+ recognition.onresult = function(event) {
122
+ const transcript = event.results[0][0].transcript.trim();
123
+ emailInput.value = transcript;
124
+ recognition.stop();
125
+
126
+ status.textContent = "Registration complete.";
127
+
128
+ // Refresh after 15 seconds
129
+ setTimeout(() => location.reload(), 15000);
130
  };
131
  }
132
 
133
+ function startProcess() {
134
+ speak("Welcome to Biryani Hub", function() {
135
+ speak("Tell me your name", startListeningForName);
136
+ });
137
+ }
138
+
139
  window.onload = function () {
140
+ setTimeout(startProcess, 1000); // Start process after 1 second
 
141
  };
142
  </script>
143
  </body>