Spaces:
Sleeping
Sleeping
<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> | |
// Initialize speech recognition | |
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; | |
const recognition = new SpeechRecognition(); | |
recognition.lang = 'en-US'; // Set language | |
// Text-to-speech | |
const synth = window.speechSynthesis; | |
// Greet the user | |
function greetUser() { | |
const greeting = "Welcome to Biryani Hub."; | |
speak(greeting); | |
document.getElementById('status').textContent = greeting; | |
// Ask for the user's name after a short delay | |
setTimeout(() => { | |
const prompt = "Tell me your name."; | |
speak(prompt); | |
document.getElementById('status').textContent = prompt; | |
}, 2000); // Wait 2 seconds before asking for the name | |
} | |
// Handle speech input | |
recognition.onresult = (event) => { | |
const transcript = event.results[0][0].transcript.trim(); | |
document.getElementById('result').textContent = `You said: ${transcript}`; | |
// Register the user's name | |
registerName(transcript); | |
}; | |
recognition.onerror = (event) => { | |
console.error('Error:', event.error); | |
document.getElementById('status').textContent = 'Error: ' + event.error; | |
}; | |
// Start listening | |
function startListening() { | |
document.getElementById('status').textContent = 'Listening...'; | |
recognition.start(); | |
} | |
// Register the user's name | |
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; | |
} | |
// Speak function | |
function speak(text) { | |
const utterance = new SpeechSynthesisUtterance(text); | |
synth.speak(utterance); | |
} | |
// Initial greeting when the page loads | |
window.onload = greetUser; | |
// Refresh the page every 15 seconds | |
setTimeout(() => { | |
window.location.reload(); | |
}, 15000); // 15 seconds | |
</script> | |
</body> | |
</html> |