|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>Biryani Hub Voice Assistant</title> |
|
<style> |
|
body { text-align: center; padding: 20px; } |
|
button { padding: 10px 20px; font-size: 16px; cursor: pointer; } |
|
#result { margin: 20px; font-size: 18px; } |
|
#username { margin: 20px; font-size: 18px; font-weight: bold; } |
|
</style> |
|
</head> |
|
<body> |
|
<h1>Biryani Hub Voice Assistant</h1> |
|
<button onclick="startListening()">Start Listening</button> |
|
<div id="result"></div> |
|
<div id="status"></div> |
|
<div id="username"></div> |
|
|
|
<script> |
|
|
|
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; |
|
const recognition = new SpeechRecognition(); |
|
recognition.lang = 'en-US'; |
|
|
|
|
|
const synth = window.speechSynthesis; |
|
|
|
|
|
function greetUser() { |
|
const greeting = "Welcome to Biryani Hub."; |
|
speak(greeting); |
|
document.getElementById('status').textContent = greeting; |
|
|
|
|
|
setTimeout(() => { |
|
const prompt = "Tell me your name."; |
|
speak(prompt); |
|
document.getElementById('status').textContent = prompt; |
|
}, 2000); |
|
} |
|
|
|
|
|
recognition.onresult = (event) => { |
|
const transcript = event.results[0][0].transcript.trim(); |
|
document.getElementById('result').textContent = `You said: ${transcript}`; |
|
|
|
|
|
registerName(transcript); |
|
}; |
|
|
|
recognition.onerror = (event) => { |
|
console.error('Error:', event.error); |
|
document.getElementById('status').textContent = 'Error: ' + event.error; |
|
}; |
|
|
|
|
|
function startListening() { |
|
document.getElementById('status').textContent = 'Listening...'; |
|
recognition.start(); |
|
} |
|
|
|
|
|
function registerName(name) { |
|
document.getElementById('username').textContent = `Registered Name: ${name}`; |
|
const response = `Thank you, ${name}. How can I assist you today?`; |
|
speak(response); |
|
document.getElementById('status').textContent = response; |
|
} |
|
|
|
|
|
function speak(text) { |
|
const utterance = new SpeechSynthesisUtterance(text); |
|
synth.speak(utterance); |
|
} |
|
|
|
|
|
window.onload = greetUser; |
|
|
|
|
|
setTimeout(() => { |
|
window.location.reload(); |
|
}, 15000); |
|
</script> |
|
</body> |
|
</html> |