File size: 3,009 Bytes
4e70d0d
 
 
 
 
b31d6fc
0e4d29e
b31d6fc
 
 
 
0e4d29e
 
 
b31d6fc
 
 
 
 
 
 
 
 
 
 
0e4d29e
b31d6fc
 
a945a59
b31d6fc
 
 
 
 
a945a59
b31d6fc
 
 
 
 
 
 
a945a59
b31d6fc
 
 
 
a945a59
b31d6fc
 
 
5419508
b31d6fc
 
 
 
9a74cb9
b31d6fc
 
 
 
8d52aa5
 
b31d6fc
 
 
 
 
 
 
5419508
b31d6fc
 
 
 
 
5419508
b31d6fc
 
5419508
b31d6fc
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!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>
        // 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>