awacke1 commited on
Commit
a0d8334
·
verified ·
1 Parent(s): 612f193

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +5 -19
index.html CHANGED
@@ -6,7 +6,7 @@
6
  <title>Voice Assistant Demo</title>
7
  <style>
8
  body {
9
- font-family: system-ui, -apple-system, sans-serif;
10
  max-width: 800px;
11
  margin: 0 auto;
12
  padding: 20px;
@@ -40,9 +40,7 @@
40
  cursor: pointer;
41
  font-size: 16px;
42
  }
43
- button:hover {
44
- background: #1976D2;
45
- }
46
  button:disabled {
47
  background: #ccc;
48
  cursor: not-allowed;
@@ -58,9 +56,7 @@
58
  background: #f8f9fa;
59
  border-radius: 4px;
60
  }
61
- .setting-group {
62
- margin: 10px 0;
63
- }
64
  label {
65
  display: inline-block;
66
  width: 100px;
@@ -114,28 +110,22 @@
114
  </div>
115
 
116
  <script>
117
- // Check if speech recognition is supported
118
  if (!('webkitSpeechRecognition' in window) && !('SpeechRecognition' in window)) {
119
  document.getElementById('error').style.display = 'block';
120
  document.getElementById('error').textContent = 'Speech recognition is not supported in this browser. Please try Chrome.';
121
  document.getElementById('startBtn').disabled = true;
122
  }
123
 
124
- // Initialize speech recognition
125
  const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
126
  const recognition = new SpeechRecognition();
127
-
128
- // Configure recognition
129
  recognition.continuous = false;
130
  recognition.lang = 'en-US';
131
  recognition.interimResults = false;
132
  recognition.maxAlternatives = 1;
133
 
134
- // Initialize speech synthesis
135
  const synth = window.speechSynthesis;
136
  let voices = [];
137
 
138
- // DOM elements
139
  const startBtn = document.getElementById('startBtn');
140
  const stopBtn = document.getElementById('stopBtn');
141
  const status = document.getElementById('status');
@@ -147,7 +137,6 @@
147
  const pitchValue = document.getElementById('pitchValue');
148
  const errorDiv = document.getElementById('error');
149
 
150
- // Populate voice list
151
  function populateVoices() {
152
  voices = synth.getVoices();
153
  voiceSelect.innerHTML = '';
@@ -164,7 +153,6 @@
164
  speechSynthesis.onvoiceschanged = populateVoices;
165
  }
166
 
167
- // Speech synthesis function
168
  function speak(text) {
169
  if (synth.speaking) {
170
  console.error('speechSynthesis.speaking');
@@ -178,7 +166,6 @@
178
  synth.speak(utterance);
179
  }
180
 
181
- // Handle commands
182
  function handleCommand(command) {
183
  command = command.toLowerCase();
184
  let response = '';
@@ -192,7 +179,7 @@
192
  const facts = [
193
  'The shortest war in history was between Britain and Zanzibar on August 27, 1896. Zanzibar surrendered after just 38 minutes.',
194
  'Honey never spoils. Archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old and still perfectly good to eat.',
195
- 'The first oranges weren't orange. The original oranges from Southeast Asia were actually green.',
196
  ];
197
  response = facts[Math.floor(Math.random() * facts.length)];
198
  } else {
@@ -203,7 +190,6 @@
203
  speak(response);
204
  }
205
 
206
- // Event listeners
207
  startBtn.addEventListener('click', () => {
208
  errorDiv.style.display = 'none';
209
  try {
@@ -259,7 +245,6 @@
259
  stopBtn.disabled = true;
260
  };
261
 
262
- // Voice setting controls
263
  rate.addEventListener('input', () => {
264
  rateValue.textContent = rate.value;
265
  });
@@ -268,5 +253,6 @@
268
  pitchValue.textContent = pitch.value;
269
  });
270
  </script>
 
271
  </body>
272
  </html>
 
6
  <title>Voice Assistant Demo</title>
7
  <style>
8
  body {
9
+ font-family: system-ui, sans-serif;
10
  max-width: 800px;
11
  margin: 0 auto;
12
  padding: 20px;
 
40
  cursor: pointer;
41
  font-size: 16px;
42
  }
43
+ button:hover { background: #1976D2; }
 
 
44
  button:disabled {
45
  background: #ccc;
46
  cursor: not-allowed;
 
56
  background: #f8f9fa;
57
  border-radius: 4px;
58
  }
59
+ .setting-group { margin: 10px 0; }
 
 
60
  label {
61
  display: inline-block;
62
  width: 100px;
 
110
  </div>
111
 
112
  <script>
 
113
  if (!('webkitSpeechRecognition' in window) && !('SpeechRecognition' in window)) {
114
  document.getElementById('error').style.display = 'block';
115
  document.getElementById('error').textContent = 'Speech recognition is not supported in this browser. Please try Chrome.';
116
  document.getElementById('startBtn').disabled = true;
117
  }
118
 
 
119
  const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
120
  const recognition = new SpeechRecognition();
 
 
121
  recognition.continuous = false;
122
  recognition.lang = 'en-US';
123
  recognition.interimResults = false;
124
  recognition.maxAlternatives = 1;
125
 
 
126
  const synth = window.speechSynthesis;
127
  let voices = [];
128
 
 
129
  const startBtn = document.getElementById('startBtn');
130
  const stopBtn = document.getElementById('stopBtn');
131
  const status = document.getElementById('status');
 
137
  const pitchValue = document.getElementById('pitchValue');
138
  const errorDiv = document.getElementById('error');
139
 
 
140
  function populateVoices() {
141
  voices = synth.getVoices();
142
  voiceSelect.innerHTML = '';
 
153
  speechSynthesis.onvoiceschanged = populateVoices;
154
  }
155
 
 
156
  function speak(text) {
157
  if (synth.speaking) {
158
  console.error('speechSynthesis.speaking');
 
166
  synth.speak(utterance);
167
  }
168
 
 
169
  function handleCommand(command) {
170
  command = command.toLowerCase();
171
  let response = '';
 
179
  const facts = [
180
  'The shortest war in history was between Britain and Zanzibar on August 27, 1896. Zanzibar surrendered after just 38 minutes.',
181
  'Honey never spoils. Archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old and still perfectly good to eat.',
182
+ 'The first oranges weren't orange. The original oranges from Southeast Asia were actually green.'
183
  ];
184
  response = facts[Math.floor(Math.random() * facts.length)];
185
  } else {
 
190
  speak(response);
191
  }
192
 
 
193
  startBtn.addEventListener('click', () => {
194
  errorDiv.style.display = 'none';
195
  try {
 
245
  stopBtn.disabled = true;
246
  };
247
 
 
248
  rate.addEventListener('input', () => {
249
  rateValue.textContent = rate.value;
250
  });
 
253
  pitchValue.textContent = pitch.value;
254
  });
255
  </script>
256
+ </div>
257
  </body>
258
  </html>