Spaces:
Running
Running
Update index.html
Browse files- index.html +222 -22
index.html
CHANGED
|
@@ -1,29 +1,229 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
-
|
| 4 |
<head>
|
| 5 |
-
<meta charset="UTF-8"
|
| 6 |
-
<
|
| 7 |
-
|
| 8 |
-
<
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
</head>
|
| 11 |
-
|
| 12 |
<body>
|
| 13 |
-
<
|
| 14 |
-
|
| 15 |
-
<
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
</
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
|
|
|
| 3 |
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 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;
|
| 13 |
+
background: #f0f0f0;
|
| 14 |
+
}
|
| 15 |
+
.container {
|
| 16 |
+
background: white;
|
| 17 |
+
padding: 20px;
|
| 18 |
+
border-radius: 8px;
|
| 19 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 20 |
+
}
|
| 21 |
+
.status {
|
| 22 |
+
margin: 20px 0;
|
| 23 |
+
padding: 10px;
|
| 24 |
+
border-radius: 4px;
|
| 25 |
+
background: #e8f5e9;
|
| 26 |
+
}
|
| 27 |
+
.transcript {
|
| 28 |
+
margin: 20px 0;
|
| 29 |
+
padding: 15px;
|
| 30 |
+
background: #f5f5f5;
|
| 31 |
+
border-radius: 4px;
|
| 32 |
+
min-height: 50px;
|
| 33 |
+
}
|
| 34 |
+
button {
|
| 35 |
+
background: #2196F3;
|
| 36 |
+
color: white;
|
| 37 |
+
border: none;
|
| 38 |
+
padding: 10px 20px;
|
| 39 |
+
border-radius: 4px;
|
| 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;
|
| 49 |
+
}
|
| 50 |
+
.controls {
|
| 51 |
+
display: flex;
|
| 52 |
+
gap: 10px;
|
| 53 |
+
margin: 20px 0;
|
| 54 |
+
}
|
| 55 |
+
.voice-settings {
|
| 56 |
+
margin: 20px 0;
|
| 57 |
+
padding: 15px;
|
| 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;
|
| 67 |
+
}
|
| 68 |
+
</style>
|
| 69 |
</head>
|
|
|
|
| 70 |
<body>
|
| 71 |
+
<div class="container">
|
| 72 |
+
<h1>Voice Assistant Demo</h1>
|
| 73 |
+
<p>Click "Start Listening" and speak a command. Try saying:</p>
|
| 74 |
+
<ul>
|
| 75 |
+
<li>"Hello" - The assistant will greet you back</li>
|
| 76 |
+
<li>"What time is it?" - Get the current time</li>
|
| 77 |
+
<li>"Tell me a fact" - Hear an interesting fact</li>
|
| 78 |
+
</ul>
|
| 79 |
+
|
| 80 |
+
<div class="controls">
|
| 81 |
+
<button id="startBtn">Start Listening</button>
|
| 82 |
+
<button id="stopBtn" disabled>Stop Listening</button>
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<div class="status" id="status">Status: Ready</div>
|
| 86 |
+
<div class="transcript" id="transcript"></div>
|
| 87 |
+
|
| 88 |
+
<div class="voice-settings">
|
| 89 |
+
<h3>Voice Settings</h3>
|
| 90 |
+
<div class="setting-group">
|
| 91 |
+
<label for="voice">Voice:</label>
|
| 92 |
+
<select id="voice"></select>
|
| 93 |
+
</div>
|
| 94 |
+
<div class="setting-group">
|
| 95 |
+
<label for="rate">Rate:</label>
|
| 96 |
+
<input type="range" id="rate" min="0.5" max="2" value="1" step="0.1">
|
| 97 |
+
<span id="rateValue">1</span>
|
| 98 |
+
</div>
|
| 99 |
+
<div class="setting-group">
|
| 100 |
+
<label for="pitch">Pitch:</label>
|
| 101 |
+
<input type="range" id="pitch" min="0.5" max="2" value="1" step="0.1">
|
| 102 |
+
<span id="pitchValue">1</span>
|
| 103 |
+
</div>
|
| 104 |
+
</div>
|
| 105 |
+
</div>
|
| 106 |
+
|
| 107 |
+
<script>
|
| 108 |
+
// Initialize speech recognition
|
| 109 |
+
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
| 110 |
+
const recognition = new SpeechRecognition();
|
| 111 |
+
recognition.continuous = false;
|
| 112 |
+
recognition.lang = 'en-US';
|
| 113 |
+
recognition.interimResults = false;
|
| 114 |
+
recognition.maxAlternatives = 1;
|
| 115 |
+
|
| 116 |
+
// Initialize speech synthesis
|
| 117 |
+
const synth = window.speechSynthesis;
|
| 118 |
+
let voices = [];
|
| 119 |
+
|
| 120 |
+
// DOM elements
|
| 121 |
+
const startBtn = document.getElementById('startBtn');
|
| 122 |
+
const stopBtn = document.getElementById('stopBtn');
|
| 123 |
+
const status = document.getElementById('status');
|
| 124 |
+
const transcript = document.getElementById('transcript');
|
| 125 |
+
const voiceSelect = document.getElementById('voice');
|
| 126 |
+
const rate = document.getElementById('rate');
|
| 127 |
+
const pitch = document.getElementById('pitch');
|
| 128 |
+
const rateValue = document.getElementById('rateValue');
|
| 129 |
+
const pitchValue = document.getElementById('pitchValue');
|
| 130 |
+
|
| 131 |
+
// Populate voice list
|
| 132 |
+
function populateVoices() {
|
| 133 |
+
voices = synth.getVoices();
|
| 134 |
+
voiceSelect.innerHTML = '';
|
| 135 |
+
voices.forEach((voice, i) => {
|
| 136 |
+
const option = document.createElement('option');
|
| 137 |
+
option.textContent = `${voice.name} (${voice.lang})`;
|
| 138 |
+
option.setAttribute('data-name', voice.name);
|
| 139 |
+
voiceSelect.appendChild(option);
|
| 140 |
+
});
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
populateVoices();
|
| 144 |
+
if (speechSynthesis.onvoiceschanged !== undefined) {
|
| 145 |
+
speechSynthesis.onvoiceschanged = populateVoices;
|
| 146 |
+
}
|
| 147 |
|
| 148 |
+
// Speech synthesis function
|
| 149 |
+
function speak(text) {
|
| 150 |
+
if (synth.speaking) {
|
| 151 |
+
synth.cancel();
|
| 152 |
+
}
|
| 153 |
+
const utterance = new SpeechSynthesisUtterance(text);
|
| 154 |
+
const selectedVoice = voices[voiceSelect.selectedIndex];
|
| 155 |
+
utterance.voice = selectedVoice;
|
| 156 |
+
utterance.rate = rate.value;
|
| 157 |
+
utterance.pitch = pitch.value;
|
| 158 |
+
synth.speak(utterance);
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
// Handle commands
|
| 162 |
+
function handleCommand(command) {
|
| 163 |
+
command = command.toLowerCase();
|
| 164 |
+
let response = '';
|
| 165 |
+
|
| 166 |
+
if (command.includes('hello')) {
|
| 167 |
+
response = 'Hello! How can I help you today?';
|
| 168 |
+
} else if (command.includes('what time')) {
|
| 169 |
+
const now = new Date();
|
| 170 |
+
response = `The current time is ${now.toLocaleTimeString()}`;
|
| 171 |
+
} else if (command.includes('tell me a fact')) {
|
| 172 |
+
const facts = [
|
| 173 |
+
'The shortest war in history was between Britain and Zanzibar on August 27, 1896. Zanzibar surrendered after just 38 minutes.',
|
| 174 |
+
'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.',
|
| 175 |
+
'The first oranges weren't orange. The original oranges from Southeast Asia were actually green.',
|
| 176 |
+
];
|
| 177 |
+
response = facts[Math.floor(Math.random() * facts.length)];
|
| 178 |
+
} else {
|
| 179 |
+
response = "I'm sorry, I didn't understand that command. Please try again.";
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
transcript.textContent = `You said: ${command}\nAssistant: ${response}`;
|
| 183 |
+
speak(response);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
// Event listeners
|
| 187 |
+
startBtn.addEventListener('click', () => {
|
| 188 |
+
recognition.start();
|
| 189 |
+
startBtn.disabled = true;
|
| 190 |
+
stopBtn.disabled = false;
|
| 191 |
+
status.textContent = 'Status: Listening...';
|
| 192 |
+
});
|
| 193 |
+
|
| 194 |
+
stopBtn.addEventListener('click', () => {
|
| 195 |
+
recognition.stop();
|
| 196 |
+
startBtn.disabled = false;
|
| 197 |
+
stopBtn.disabled = true;
|
| 198 |
+
status.textContent = 'Status: Stopped';
|
| 199 |
+
});
|
| 200 |
+
|
| 201 |
+
recognition.addEventListener('result', (event) => {
|
| 202 |
+
const command = event.results[0][0].transcript;
|
| 203 |
+
handleCommand(command);
|
| 204 |
+
});
|
| 205 |
+
|
| 206 |
+
recognition.addEventListener('end', () => {
|
| 207 |
+
startBtn.disabled = false;
|
| 208 |
+
stopBtn.disabled = true;
|
| 209 |
+
status.textContent = 'Status: Ready';
|
| 210 |
+
});
|
| 211 |
+
|
| 212 |
+
recognition.addEventListener('error', (event) => {
|
| 213 |
+
status.textContent = `Status: Error - ${event.error}`;
|
| 214 |
+
startBtn.disabled = false;
|
| 215 |
+
stopBtn.disabled = true;
|
| 216 |
+
});
|
| 217 |
+
|
| 218 |
+
// Voice setting controls
|
| 219 |
+
rate.addEventListener('input', () => {
|
| 220 |
+
rateValue.textContent = rate.value;
|
| 221 |
+
});
|
| 222 |
+
|
| 223 |
+
pitch.addEventListener('input', () => {
|
| 224 |
+
pitchValue.textContent = pitch.value;
|
| 225 |
+
});
|
| 226 |
+
</script>
|
| 227 |
+
</div>
|
| 228 |
+
</body>
|
| 229 |
</html>
|