DSatishchandra commited on
Commit
a09353c
·
verified ·
1 Parent(s): 0770706

Update templates/dashboard.html

Browse files
Files changed (1) hide show
  1. templates/dashboard.html +61 -0
templates/dashboard.html CHANGED
@@ -50,6 +50,21 @@
50
  a:hover {
51
  color: #45a049;
52
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  </style>
54
  </head>
55
  <body>
@@ -58,7 +73,53 @@
58
  <h1>Welcome to the Dashboard</h1>
59
  <p>This is your user dashboard where you can access various features.</p>
60
  <a href="/menu">Go to Menu</a>
 
 
 
61
  </div>
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  </body>
64
  </html>
 
50
  a:hover {
51
  color: #45a049;
52
  }
53
+
54
+ /* Button for listening */
55
+ #listen-btn {
56
+ padding: 10px 20px;
57
+ background-color: #4CAF50;
58
+ color: white;
59
+ border: none;
60
+ border-radius: 5px;
61
+ cursor: pointer;
62
+ font-size: 1.2rem;
63
+ }
64
+
65
+ #listen-btn:hover {
66
+ background-color: #45a049;
67
+ }
68
  </style>
69
  </head>
70
  <body>
 
73
  <h1>Welcome to the Dashboard</h1>
74
  <p>This is your user dashboard where you can access various features.</p>
75
  <a href="/menu">Go to Menu</a>
76
+
77
+ <!-- Button for triggering voice recognition -->
78
+ <button id="listen-btn">Say "Go to Menu"</button>
79
  </div>
80
 
81
+ <script>
82
+ // Speech Recognition and Speech Synthesis for voice interaction
83
+
84
+ // Check for SpeechRecognition support
85
+ const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
86
+ const recognition = new SpeechRecognition();
87
+ recognition.lang = 'en-US';
88
+ recognition.interimResults = false;
89
+ recognition.maxAlternatives = 1;
90
+
91
+ // Function to speak the message
92
+ function speak(text) {
93
+ const msg = new SpeechSynthesisUtterance(text);
94
+ msg.rate = 1; // Speed of speech
95
+ window.speechSynthesis.speak(msg);
96
+ }
97
+
98
+ // Button for listening to user input
99
+ const listenButton = document.getElementById("listen-btn");
100
+
101
+ listenButton.addEventListener("click", () => {
102
+ speak("Please say 'Go to Menu' to navigate to the menu.");
103
+ recognition.start();
104
+ });
105
+
106
+ // Handle speech recognition result
107
+ recognition.onresult = (event) => {
108
+ const command = event.results[0][0].transcript.toLowerCase();
109
+ console.log("User said:", command);
110
+
111
+ // If user says "Go to Menu", navigate to the menu
112
+ if (command.includes("go to menu")) {
113
+ window.location.href = "/menu";
114
+ }
115
+ };
116
+
117
+ // Handle errors in speech recognition
118
+ recognition.onerror = (event) => {
119
+ console.error("Speech recognition error:", event.error);
120
+ speak("Sorry, I couldn't understand that. Please try again.");
121
+ };
122
+ </script>
123
+
124
  </body>
125
  </html>