Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +23 -9
templates/index.html
CHANGED
@@ -65,7 +65,7 @@
|
|
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...</p>
|
69 |
<p class="status" id="status">Initializing...</p>
|
70 |
</div>
|
71 |
|
@@ -73,30 +73,38 @@
|
|
73 |
let recognition;
|
74 |
let nameCaptured = "";
|
75 |
let emailCaptured = "";
|
|
|
76 |
if ('webkitSpeechRecognition' in window) {
|
77 |
recognition = new webkitSpeechRecognition();
|
78 |
-
recognition.continuous =
|
79 |
recognition.interimResults = false;
|
80 |
recognition.lang = 'en-US';
|
81 |
} else {
|
82 |
alert("Speech Recognition API is not supported in this browser.");
|
83 |
}
|
|
|
84 |
function speak(text, callback) {
|
85 |
const speech = new SpeechSynthesisUtterance(text);
|
86 |
speech.onend = callback;
|
87 |
window.speechSynthesis.speak(speech);
|
88 |
}
|
|
|
89 |
function startListeningForName() {
|
|
|
90 |
recognition.start();
|
91 |
recognition.onresult = function(event) {
|
92 |
-
|
|
|
93 |
document.getElementById('name').value = nameCaptured;
|
|
|
|
|
94 |
recognition.stop();
|
95 |
setTimeout(confirmName, 500);
|
96 |
};
|
97 |
}
|
|
|
98 |
function confirmName() {
|
99 |
-
speak("You said " + nameCaptured + ". Is it okay, or do you want to change it?", function() {
|
100 |
recognition.start();
|
101 |
recognition.onresult = function(event) {
|
102 |
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
|
@@ -104,16 +112,21 @@
|
|
104 |
if (confirmation.includes("ok") || confirmation.includes("yes")) {
|
105 |
setTimeout(() => speak("Great! Now, tell me your email.", startListeningForEmail), 500);
|
106 |
} else {
|
107 |
-
setTimeout(() => speak("Let's try again. Tell me your name.", startListeningForName), 500);
|
108 |
}
|
109 |
};
|
110 |
});
|
111 |
}
|
|
|
112 |
function startListeningForEmail() {
|
|
|
113 |
recognition.start();
|
114 |
recognition.onresult = function(event) {
|
115 |
-
|
|
|
116 |
document.getElementById('email').value = emailCaptured;
|
|
|
|
|
117 |
recognition.stop();
|
118 |
speak("You said " + emailCaptured + ". Is it correct?", function() {
|
119 |
recognition.start();
|
@@ -124,23 +137,24 @@
|
|
124 |
speak("Your registration is complete. Thank you for registering.");
|
125 |
setTimeout(() => location.reload(), 20000);
|
126 |
} else {
|
127 |
-
speak("Let's try again. Tell me your email.", startListeningForEmail);
|
128 |
}
|
129 |
};
|
130 |
});
|
131 |
};
|
132 |
}
|
|
|
133 |
function startProcess() {
|
134 |
speak("Welcome to Biryani Hub", function() {
|
135 |
-
speak("Tell me your name, and I will confirm it with you.", function() {
|
136 |
setTimeout(startListeningForName, 500);
|
137 |
});
|
138 |
});
|
139 |
}
|
|
|
140 |
window.onload = function () {
|
141 |
setTimeout(startProcess, 4000);
|
142 |
};
|
143 |
</script>
|
144 |
</body>
|
145 |
</html>
|
146 |
-
|
|
|
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 |
|
|
|
73 |
let recognition;
|
74 |
let nameCaptured = "";
|
75 |
let emailCaptured = "";
|
76 |
+
|
77 |
if ('webkitSpeechRecognition' in window) {
|
78 |
recognition = new webkitSpeechRecognition();
|
79 |
+
recognition.continuous = true;
|
80 |
recognition.interimResults = false;
|
81 |
recognition.lang = 'en-US';
|
82 |
} else {
|
83 |
alert("Speech Recognition API is not supported in this browser.");
|
84 |
}
|
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 |
+
nameCaptured = "";
|
94 |
recognition.start();
|
95 |
recognition.onresult = function(event) {
|
96 |
+
let transcript = event.results[event.results.length - 1][0].transcript.trim().replace(/\s+/g, "");
|
97 |
+
nameCaptured += transcript;
|
98 |
document.getElementById('name').value = nameCaptured;
|
99 |
+
};
|
100 |
+
recognition.onspeechend = function() {
|
101 |
recognition.stop();
|
102 |
setTimeout(confirmName, 500);
|
103 |
};
|
104 |
}
|
105 |
+
|
106 |
function confirmName() {
|
107 |
+
speak("You said " + nameCaptured.split('').join(' ') + ". Is it okay, or do you want to change it?", function() {
|
108 |
recognition.start();
|
109 |
recognition.onresult = function(event) {
|
110 |
let confirmation = event.results[0][0].transcript.trim().toLowerCase();
|
|
|
112 |
if (confirmation.includes("ok") || confirmation.includes("yes")) {
|
113 |
setTimeout(() => speak("Great! Now, tell me your email.", startListeningForEmail), 500);
|
114 |
} else {
|
115 |
+
setTimeout(() => speak("Let's try again. Tell me your name, letter by letter.", startListeningForName), 500);
|
116 |
}
|
117 |
};
|
118 |
});
|
119 |
}
|
120 |
+
|
121 |
function startListeningForEmail() {
|
122 |
+
emailCaptured = "";
|
123 |
recognition.start();
|
124 |
recognition.onresult = function(event) {
|
125 |
+
let transcript = event.results[event.results.length - 1][0].transcript.trim().replace(/\s+/g, "");
|
126 |
+
emailCaptured += transcript;
|
127 |
document.getElementById('email').value = emailCaptured;
|
128 |
+
};
|
129 |
+
recognition.onspeechend = function() {
|
130 |
recognition.stop();
|
131 |
speak("You said " + emailCaptured + ". Is it correct?", function() {
|
132 |
recognition.start();
|
|
|
137 |
speak("Your registration is complete. Thank you for registering.");
|
138 |
setTimeout(() => location.reload(), 20000);
|
139 |
} else {
|
140 |
+
speak("Let's try again. Tell me your email letter by letter.", startListeningForEmail);
|
141 |
}
|
142 |
};
|
143 |
});
|
144 |
};
|
145 |
}
|
146 |
+
|
147 |
function startProcess() {
|
148 |
speak("Welcome to Biryani Hub", function() {
|
149 |
+
speak("Tell me your name letter by letter, and I will confirm it with you.", function() {
|
150 |
setTimeout(startListeningForName, 500);
|
151 |
});
|
152 |
});
|
153 |
}
|
154 |
+
|
155 |
window.onload = function () {
|
156 |
setTimeout(startProcess, 4000);
|
157 |
};
|
158 |
</script>
|
159 |
</body>
|
160 |
</html>
|
|