atlury commited on
Commit
0eb6a81
·
verified ·
1 Parent(s): 055955e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +108 -46
index.html CHANGED
@@ -10,15 +10,24 @@
10
  <style>
11
  body {
12
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
 
 
 
 
 
 
13
  max-width: 800px;
14
  margin: 0 auto;
15
- padding: 20px;
16
- background-color: #f0f0f0;
17
- color: #333;
18
  }
19
  h1 {
 
 
 
 
 
20
  text-align: center;
21
- color: #2c3e50;
 
22
  }
23
  #chat-container {
24
  display: flex;
@@ -27,48 +36,47 @@
27
  }
28
  #conversation {
29
  flex-grow: 1;
30
- border: 1px solid #ccc;
31
  padding: 10px;
32
  overflow-y: scroll;
33
- background-color: white;
34
  border-radius: 5px;
35
- box-shadow: 0 2px 5px rgba(0,0,0,0.1);
36
  }
37
  #controls {
38
  display: flex;
39
  justify-content: center;
40
- margin-top: 20px;
41
  }
42
  button {
43
  font-size: 18px;
44
  padding: 10px 20px;
45
- margin: 0 10px;
46
- background-color: #3498db;
47
- color: white;
48
  border: none;
49
  border-radius: 5px;
50
  cursor: pointer;
51
  transition: background-color 0.3s;
52
  }
53
  button:hover {
54
- background-color: #2980b9;
55
  }
56
  button:disabled {
57
- background-color: #bdc3c7;
58
  cursor: not-allowed;
59
  }
60
  #visualizer {
61
  width: 100%;
62
  height: 100px;
63
- background-color: #34495e;
64
- margin-top: 20px;
65
  border-radius: 5px;
66
  overflow: hidden;
 
67
  }
68
  .bar {
69
  width: 5px;
70
  height: 100%;
71
- background-color: #3498db;
72
  display: inline-block;
73
  margin-right: 1px;
74
  }
@@ -78,7 +86,7 @@
78
  left: 0;
79
  width: 100%;
80
  height: 100%;
81
- background-color: rgba(0, 0, 0, 0.5);
82
  display: flex;
83
  justify-content: center;
84
  align-items: center;
@@ -88,7 +96,7 @@
88
  width: 50px;
89
  height: 50px;
90
  border: 5px solid #f3f3f3;
91
- border-top: 5px solid #3498db;
92
  border-radius: 50%;
93
  animation: spin 1s linear infinite;
94
  }
@@ -96,20 +104,67 @@
96
  0% { transform: rotate(0deg); }
97
  100% { transform: rotate(360deg); }
98
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  </style>
100
  </head>
101
  <body>
102
  <div id="loading">
103
  <div class="spinner"></div>
104
  </div>
105
- <h1>Voice Chat Bot</h1>
106
- <div id="chat-container">
107
- <div id="conversation"></div>
108
- <div id="visualizer"></div>
109
- <div id="controls">
110
- <button id="startButton" disabled>Start Listening</button>
111
- <button id="stopButton" disabled>Stop Listening</button>
 
 
 
 
 
 
 
 
 
 
 
 
112
  </div>
 
 
 
113
  </div>
114
 
115
  <script type="module">
@@ -119,9 +174,10 @@
119
 
120
  const conversationDiv = document.getElementById('conversation');
121
  const startButton = document.getElementById('startButton');
122
- const stopButton = document.getElementById('stopButton');
123
  const visualizer = document.getElementById('visualizer');
124
  const loadingDiv = document.getElementById('loading');
 
 
125
 
126
  let myvad;
127
  let sttPipeline;
@@ -157,12 +213,12 @@
157
  ttsPipeline = await pipeline('text-to-speech', 'Xenova/mms-tts-eng', {
158
  quantized: false,
159
  });
160
- addMessage('System', 'Voice Chat Bot initialized. Click "Start Listening" to begin.');
161
  startButton.disabled = false;
162
  loadingDiv.style.display = 'none';
163
  } catch (error) {
164
  console.error('Error initializing pipelines:', error);
165
- addMessage('System', 'Error initializing Voice Chat Bot. Please check the console for details.');
166
  loadingDiv.style.display = 'none';
167
  }
168
  }
@@ -174,24 +230,27 @@
174
  }
175
 
176
  const transcription = await sttPipeline(audio);
177
- addMessage('User', transcription.text);
178
 
179
  const botResponse = `I heard you say: "${transcription.text}". This is a placeholder response.`;
180
- addMessage('Bot', botResponse);
181
 
182
  const speechOutput = await ttsPipeline(botResponse);
183
  playAudio(speechOutput.audio);
184
  } catch (error) {
185
  console.error('Error processing speech:', error);
186
- addMessage('System', 'Error processing speech. Please try again.');
187
  }
188
  }
189
 
190
- function addMessage(sender, message) {
191
- const messageElement = document.createElement('p');
192
- messageElement.innerHTML = `<strong>${sender}:</strong> ${message}`;
193
- conversationDiv.appendChild(messageElement);
194
- conversationDiv.scrollTop = conversationDiv.scrollHeight;
 
 
 
195
  }
196
 
197
  function playAudio(audioArray) {
@@ -215,11 +274,11 @@
215
 
216
  myvad = await vad.MicVAD.new({
217
  onSpeechStart: () => {
218
- console.log('Speech started');
219
  updateVisualizer();
220
  },
221
  onSpeechEnd: (audio) => {
222
- console.log('Speech ended');
223
  cancelAnimationFrame(animationId);
224
  processSpeech(audio);
225
  }
@@ -230,27 +289,30 @@
230
  source.connect(analyser);
231
 
232
  await myvad.start();
233
- startButton.disabled = true;
234
- stopButton.disabled = false;
235
- addMessage('System', 'Listening...');
236
  } catch (error) {
237
  console.error('Error starting VAD:', error);
238
- addMessage('System', 'Error starting voice detection. Please check your microphone and try again.');
239
  }
240
  }
241
 
242
  function stopListening() {
243
  if (myvad) {
244
  myvad.pause();
245
- startButton.disabled = false;
246
- stopButton.disabled = true;
247
- addMessage('System', 'Stopped listening.');
248
  cancelAnimationFrame(animationId);
 
249
  }
250
  }
251
 
252
  startButton.addEventListener('click', startListening);
253
- stopButton.addEventListener('click', stopListening);
 
 
254
 
255
  createVisualizer();
256
  initializePipelines();
 
10
  <style>
11
  body {
12
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
13
+ margin: 0;
14
+ padding: 20px;
15
+ background-color: #1a1a1a;
16
+ color: #f0f0f0;
17
+ }
18
+ .container {
19
  max-width: 800px;
20
  margin: 0 auto;
 
 
 
21
  }
22
  h1 {
23
+ color: #ffd700;
24
+ text-align: center;
25
+ margin-bottom: 10px;
26
+ }
27
+ .subtitle {
28
  text-align: center;
29
+ color: #ffd700;
30
+ margin-bottom: 20px;
31
  }
32
  #chat-container {
33
  display: flex;
 
36
  }
37
  #conversation {
38
  flex-grow: 1;
39
+ border: 1px solid #444;
40
  padding: 10px;
41
  overflow-y: scroll;
42
+ background-color: #2a2a2a;
43
  border-radius: 5px;
44
+ margin-bottom: 20px;
45
  }
46
  #controls {
47
  display: flex;
48
  justify-content: center;
49
+ margin-bottom: 20px;
50
  }
51
  button {
52
  font-size: 18px;
53
  padding: 10px 20px;
54
+ background-color: #ffd700;
55
+ color: #1a1a1a;
 
56
  border: none;
57
  border-radius: 5px;
58
  cursor: pointer;
59
  transition: background-color 0.3s;
60
  }
61
  button:hover {
62
+ background-color: #ffec8b;
63
  }
64
  button:disabled {
65
+ background-color: #666;
66
  cursor: not-allowed;
67
  }
68
  #visualizer {
69
  width: 100%;
70
  height: 100px;
71
+ background-color: #2a2a2a;
 
72
  border-radius: 5px;
73
  overflow: hidden;
74
+ margin-bottom: 20px;
75
  }
76
  .bar {
77
  width: 5px;
78
  height: 100%;
79
+ background-color: #ffd700;
80
  display: inline-block;
81
  margin-right: 1px;
82
  }
 
86
  left: 0;
87
  width: 100%;
88
  height: 100%;
89
+ background-color: rgba(0, 0, 0, 0.8);
90
  display: flex;
91
  justify-content: center;
92
  align-items: center;
 
96
  width: 50px;
97
  height: 50px;
98
  border: 5px solid #f3f3f3;
99
+ border-top: 5px solid #ffd700;
100
  border-radius: 50%;
101
  animation: spin 1s linear infinite;
102
  }
 
104
  0% { transform: rotate(0deg); }
105
  100% { transform: rotate(360deg); }
106
  }
107
+ #configuration {
108
+ margin-bottom: 20px;
109
+ }
110
+ select {
111
+ width: 100%;
112
+ padding: 10px;
113
+ font-size: 16px;
114
+ background-color: #2a2a2a;
115
+ color: #f0f0f0;
116
+ border: 1px solid #444;
117
+ border-radius: 5px;
118
+ }
119
+ #model-info {
120
+ margin-top: 10px;
121
+ font-size: 14px;
122
+ color: #aaa;
123
+ }
124
+ #logs {
125
+ background-color: #2a2a2a;
126
+ border: 1px solid #444;
127
+ border-radius: 5px;
128
+ padding: 10px;
129
+ height: 200px;
130
+ overflow-y: scroll;
131
+ font-family: monospace;
132
+ font-size: 14px;
133
+ }
134
+ #clear-logs {
135
+ margin-top: 10px;
136
+ font-size: 14px;
137
+ padding: 5px 10px;
138
+ }
139
  </style>
140
  </head>
141
  <body>
142
  <div id="loading">
143
  <div class="spinner"></div>
144
  </div>
145
+ <div class="container">
146
+ <h1>Voice Chat Bot Demo</h1>
147
+ <p class="subtitle">For best results, use headphones.</p>
148
+ <div id="chat-container">
149
+ <div id="controls">
150
+ <button id="startButton" disabled>Begin Call</button>
151
+ </div>
152
+ <div id="configuration">
153
+ <select id="configSelect">
154
+ <option value="fastest">Fastest</option>
155
+ <option value="balanced">Balanced</option>
156
+ <option value="quality">Highest Quality</option>
157
+ </select>
158
+ <div id="model-info">
159
+ TTS: Xenova/mms-tts-eng / STT: Xenova/whisper-tiny.en / LLM: Placeholder
160
+ </div>
161
+ </div>
162
+ <div id="visualizer"></div>
163
+ <div id="conversation"></div>
164
  </div>
165
+ <h2>Logs</h2>
166
+ <div id="logs"></div>
167
+ <button id="clear-logs">Clear</button>
168
  </div>
169
 
170
  <script type="module">
 
174
 
175
  const conversationDiv = document.getElementById('conversation');
176
  const startButton = document.getElementById('startButton');
 
177
  const visualizer = document.getElementById('visualizer');
178
  const loadingDiv = document.getElementById('loading');
179
+ const logsDiv = document.getElementById('logs');
180
+ const clearLogsButton = document.getElementById('clear-logs');
181
 
182
  let myvad;
183
  let sttPipeline;
 
213
  ttsPipeline = await pipeline('text-to-speech', 'Xenova/mms-tts-eng', {
214
  quantized: false,
215
  });
216
+ addLog('System: Voice Chat Bot initialized. Click "Begin Call" to start.');
217
  startButton.disabled = false;
218
  loadingDiv.style.display = 'none';
219
  } catch (error) {
220
  console.error('Error initializing pipelines:', error);
221
+ addLog('System: Error initializing Voice Chat Bot. Please check the console for details.');
222
  loadingDiv.style.display = 'none';
223
  }
224
  }
 
230
  }
231
 
232
  const transcription = await sttPipeline(audio);
233
+ addLog(`User: ${transcription.text}`);
234
 
235
  const botResponse = `I heard you say: "${transcription.text}". This is a placeholder response.`;
236
+ addLog(`Bot: ${botResponse}`);
237
 
238
  const speechOutput = await ttsPipeline(botResponse);
239
  playAudio(speechOutput.audio);
240
  } catch (error) {
241
  console.error('Error processing speech:', error);
242
+ addLog('System: Error processing speech. Please try again.');
243
  }
244
  }
245
 
246
+ function addLog(message) {
247
+ const now = new Date();
248
+ const timestamp = now.toLocaleTimeString();
249
+ const logMessage = `[${timestamp}] ${message}`;
250
+ const messageElement = document.createElement('div');
251
+ messageElement.textContent = logMessage;
252
+ logsDiv.appendChild(messageElement);
253
+ logsDiv.scrollTop = logsDiv.scrollHeight;
254
  }
255
 
256
  function playAudio(audioArray) {
 
274
 
275
  myvad = await vad.MicVAD.new({
276
  onSpeechStart: () => {
277
+ addLog('--- vad: speech start');
278
  updateVisualizer();
279
  },
280
  onSpeechEnd: (audio) => {
281
+ addLog('--- vad: speech end');
282
  cancelAnimationFrame(animationId);
283
  processSpeech(audio);
284
  }
 
289
  source.connect(analyser);
290
 
291
  await myvad.start();
292
+ startButton.textContent = 'End Call';
293
+ startButton.onclick = stopListening;
294
+ addLog('System: Listening...');
295
  } catch (error) {
296
  console.error('Error starting VAD:', error);
297
+ addLog('System: Error starting voice detection. Please check your microphone and try again.');
298
  }
299
  }
300
 
301
  function stopListening() {
302
  if (myvad) {
303
  myvad.pause();
304
+ startButton.textContent = 'Begin Call';
305
+ startButton.onclick = startListening;
306
+ addLog('System: Stopped listening.');
307
  cancelAnimationFrame(animationId);
308
+ addLog('websocket closed');
309
  }
310
  }
311
 
312
  startButton.addEventListener('click', startListening);
313
+ clearLogsButton.addEventListener('click', () => {
314
+ logsDiv.innerHTML = '';
315
+ });
316
 
317
  createVisualizer();
318
  initializePipelines();