Spaces:
Running
Running
Add 2 files
Browse files- index.html +257 -5
- prompts.txt +2 -1
index.html
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>
|
7 |
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
9 |
<style>
|
@@ -60,18 +60,73 @@
|
|
60 |
.format-option {
|
61 |
transition: all 0.3s ease;
|
62 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
</style>
|
64 |
</head>
|
65 |
<body class="bg-gray-100 min-h-screen">
|
66 |
<div class="container mx-auto px-4 py-8">
|
67 |
<div class="max-w-3xl mx-auto">
|
68 |
<div class="text-center mb-8">
|
69 |
-
<h1 class="text-4xl font-bold text-gray-800 mb-2">
|
70 |
-
<p class="text-gray-600">
|
71 |
</div>
|
72 |
|
73 |
<div class="bg-white rounded-xl shadow-lg overflow-hidden mb-8">
|
74 |
<div class="p-6">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
<div class="waveform mb-6" id="waveform"></div>
|
76 |
|
77 |
<div class="flex flex-col sm:flex-row justify-center items-center gap-4 mb-6">
|
@@ -147,6 +202,12 @@
|
|
147 |
let audioElement;
|
148 |
let timerInterval;
|
149 |
let seconds = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
// DOM elements
|
152 |
const recordBtn = document.getElementById('recordBtn');
|
@@ -156,9 +217,24 @@
|
|
156 |
const timer = document.getElementById('timer');
|
157 |
const recordingsList = document.getElementById('recordingsList');
|
158 |
const formatOptions = document.querySelectorAll('.format-option');
|
|
|
|
|
|
|
|
|
159 |
|
160 |
let selectedFormat = 'wav'; // Default format
|
161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
// Format selection
|
163 |
formatOptions.forEach(option => {
|
164 |
option.addEventListener('click', function() {
|
@@ -171,10 +247,180 @@
|
|
171 |
// Set first format as selected by default
|
172 |
formatOptions[0].classList.add('ring-2', 'ring-indigo-500');
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
// Request permission to use microphone
|
175 |
recordBtn.addEventListener('click', async function() {
|
176 |
try {
|
177 |
-
const
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
mediaRecorder = new MediaRecorder(stream);
|
180 |
audioChunks = [];
|
@@ -196,6 +442,11 @@
|
|
196 |
|
197 |
// Add to recordings list
|
198 |
addRecordingToList(audioUrl);
|
|
|
|
|
|
|
|
|
|
|
199 |
};
|
200 |
|
201 |
mediaRecorder.start(10); // Collect data every 10ms
|
@@ -229,7 +480,7 @@
|
|
229 |
mediaRecorder.stop();
|
230 |
|
231 |
// Stop all tracks in the stream
|
232 |
-
|
233 |
|
234 |
// Clear timer
|
235 |
clearInterval(timerInterval);
|
@@ -301,6 +552,7 @@
|
|
301 |
<div>
|
302 |
<p class="font-medium">Recording ${recordingsList.children.length + 1}</p>
|
303 |
<p class="text-sm text-gray-500">${new Date().toLocaleString()}</p>
|
|
|
304 |
</div>
|
305 |
</div>
|
306 |
<div class="flex gap-2">
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Advanced Audio Recorder</title>
|
7 |
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
9 |
<style>
|
|
|
60 |
.format-option {
|
61 |
transition: all 0.3s ease;
|
62 |
}
|
63 |
+
|
64 |
+
.device-option:hover {
|
65 |
+
background-color: #f3f4f6;
|
66 |
+
}
|
67 |
+
|
68 |
+
.device-option {
|
69 |
+
transition: all 0.2s ease;
|
70 |
+
}
|
71 |
+
|
72 |
+
.visualizer {
|
73 |
+
width: 100%;
|
74 |
+
height: 80px;
|
75 |
+
background-color: #f3f4f6;
|
76 |
+
border-radius: 0.5rem;
|
77 |
+
position: relative;
|
78 |
+
overflow: hidden;
|
79 |
+
}
|
80 |
+
|
81 |
+
.bar {
|
82 |
+
position: absolute;
|
83 |
+
bottom: 0;
|
84 |
+
width: 8px;
|
85 |
+
background-color: #3b82f6;
|
86 |
+
border-radius: 4px 4px 0 0;
|
87 |
+
transition: height 0.1s ease;
|
88 |
+
}
|
89 |
</style>
|
90 |
</head>
|
91 |
<body class="bg-gray-100 min-h-screen">
|
92 |
<div class="container mx-auto px-4 py-8">
|
93 |
<div class="max-w-3xl mx-auto">
|
94 |
<div class="text-center mb-8">
|
95 |
+
<h1 class="text-4xl font-bold text-gray-800 mb-2">Advanced Audio Recorder</h1>
|
96 |
+
<p class="text-gray-600">Select your input device, record, and download in multiple formats</p>
|
97 |
</div>
|
98 |
|
99 |
<div class="bg-white rounded-xl shadow-lg overflow-hidden mb-8">
|
100 |
<div class="p-6">
|
101 |
+
<!-- Device Selection Section -->
|
102 |
+
<div class="mb-6">
|
103 |
+
<h3 class="text-lg font-semibold text-gray-800 mb-3">Select Input Device</h3>
|
104 |
+
<div class="flex flex-col sm:flex-row gap-4 mb-4">
|
105 |
+
<div class="flex-1">
|
106 |
+
<label for="audioSource" class="block text-sm font-medium text-gray-700 mb-1">Audio Input</label>
|
107 |
+
<select id="audioSource" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border">
|
108 |
+
<option value="">Default</option>
|
109 |
+
</select>
|
110 |
+
</div>
|
111 |
+
<div class="flex-1">
|
112 |
+
<label for="audioQuality" class="block text-sm font-medium text-gray-700 mb-1">Quality</label>
|
113 |
+
<select id="audioQuality" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border">
|
114 |
+
<option value="high">High (CD Quality)</option>
|
115 |
+
<option value="medium" selected>Medium (Good Quality)</option>
|
116 |
+
<option value="low">Low (Voice Only)</option>
|
117 |
+
</select>
|
118 |
+
</div>
|
119 |
+
</div>
|
120 |
+
|
121 |
+
<div class="visualizer mb-4" id="visualizer">
|
122 |
+
<!-- Audio bars will be inserted here by JavaScript -->
|
123 |
+
</div>
|
124 |
+
|
125 |
+
<div class="text-center text-sm text-gray-500" id="deviceStatus">
|
126 |
+
<i class="fas fa-microphone-slash mr-1"></i> No device selected
|
127 |
+
</div>
|
128 |
+
</div>
|
129 |
+
|
130 |
<div class="waveform mb-6" id="waveform"></div>
|
131 |
|
132 |
<div class="flex flex-col sm:flex-row justify-center items-center gap-4 mb-6">
|
|
|
202 |
let audioElement;
|
203 |
let timerInterval;
|
204 |
let seconds = 0;
|
205 |
+
let audioContext;
|
206 |
+
let analyser;
|
207 |
+
let microphone;
|
208 |
+
let dataArray;
|
209 |
+
let animationId;
|
210 |
+
let currentStream;
|
211 |
|
212 |
// DOM elements
|
213 |
const recordBtn = document.getElementById('recordBtn');
|
|
|
217 |
const timer = document.getElementById('timer');
|
218 |
const recordingsList = document.getElementById('recordingsList');
|
219 |
const formatOptions = document.querySelectorAll('.format-option');
|
220 |
+
const audioSourceSelect = document.getElementById('audioSource');
|
221 |
+
const audioQualitySelect = document.getElementById('audioQuality');
|
222 |
+
const visualizer = document.getElementById('visualizer');
|
223 |
+
const deviceStatus = document.getElementById('deviceStatus');
|
224 |
|
225 |
let selectedFormat = 'wav'; // Default format
|
226 |
|
227 |
+
// Create audio bars for visualizer
|
228 |
+
const barCount = 40;
|
229 |
+
for (let i = 0; i < barCount; i++) {
|
230 |
+
const bar = document.createElement('div');
|
231 |
+
bar.className = 'bar';
|
232 |
+
bar.style.left = `${i * (100 / barCount)}%`;
|
233 |
+
bar.style.height = '0%';
|
234 |
+
visualizer.appendChild(bar);
|
235 |
+
}
|
236 |
+
const bars = document.querySelectorAll('.bar');
|
237 |
+
|
238 |
// Format selection
|
239 |
formatOptions.forEach(option => {
|
240 |
option.addEventListener('click', function() {
|
|
|
247 |
// Set first format as selected by default
|
248 |
formatOptions[0].classList.add('ring-2', 'ring-indigo-500');
|
249 |
|
250 |
+
// Get available audio devices
|
251 |
+
async function getAudioDevices() {
|
252 |
+
try {
|
253 |
+
// First get permission by accessing media
|
254 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
255 |
+
stopStream(stream); // We don't need this stream, just needed for permission
|
256 |
+
|
257 |
+
// Now enumerate devices
|
258 |
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
259 |
+
const audioInputs = devices.filter(device => device.kind === 'audioinput');
|
260 |
+
|
261 |
+
// Clear existing options
|
262 |
+
audioSourceSelect.innerHTML = '<option value="">Default</option>';
|
263 |
+
|
264 |
+
// Add each audio input device as an option
|
265 |
+
audioInputs.forEach(device => {
|
266 |
+
const option = document.createElement('option');
|
267 |
+
option.value = device.deviceId;
|
268 |
+
option.text = device.label || `Microphone ${audioSourceSelect.length}`;
|
269 |
+
audioSourceSelect.appendChild(option);
|
270 |
+
});
|
271 |
+
|
272 |
+
return true;
|
273 |
+
} catch (error) {
|
274 |
+
console.error('Error getting audio devices:', error);
|
275 |
+
deviceStatus.innerHTML = '<i class="fas fa-exclamation-triangle mr-1"></i> Could not access microphone devices';
|
276 |
+
return false;
|
277 |
+
}
|
278 |
+
}
|
279 |
+
|
280 |
+
// Stop a media stream
|
281 |
+
function stopStream(stream) {
|
282 |
+
if (stream) {
|
283 |
+
stream.getTracks().forEach(track => track.stop());
|
284 |
+
}
|
285 |
+
}
|
286 |
+
|
287 |
+
// Visualize audio input
|
288 |
+
function visualizeAudio(stream) {
|
289 |
+
// Create audio context if it doesn't exist
|
290 |
+
if (!audioContext) {
|
291 |
+
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
292 |
+
}
|
293 |
+
|
294 |
+
// Create analyser node
|
295 |
+
analyser = audioContext.createAnalyser();
|
296 |
+
analyser.fftSize = 256;
|
297 |
+
|
298 |
+
// Create microphone source
|
299 |
+
microphone = audioContext.createMediaStreamSource(stream);
|
300 |
+
microphone.connect(analyser);
|
301 |
+
|
302 |
+
// Create data array for analysis
|
303 |
+
const bufferLength = analyser.frequencyBinCount;
|
304 |
+
dataArray = new Uint8Array(bufferLength);
|
305 |
+
|
306 |
+
// Start animation loop
|
307 |
+
function animate() {
|
308 |
+
animationId = requestAnimationFrame(animate);
|
309 |
+
analyser.getByteFrequencyData(dataArray);
|
310 |
+
|
311 |
+
// Update bars
|
312 |
+
for (let i = 0; i < bars.length; i++) {
|
313 |
+
// Scale the index to cover the full frequency range
|
314 |
+
const scaledIndex = Math.floor(i * (bufferLength / bars.length));
|
315 |
+
const value = dataArray[scaledIndex];
|
316 |
+
const height = value / 2.55; // Convert 0-255 to 0-100
|
317 |
+
bars[i].style.height = `${height}%`;
|
318 |
+
bars[i].style.backgroundColor = `hsl(${200 + (height * 1.5)}, 100%, 50%)`;
|
319 |
+
}
|
320 |
+
}
|
321 |
+
|
322 |
+
// Start animation
|
323 |
+
animate();
|
324 |
+
|
325 |
+
// Update device status
|
326 |
+
deviceStatus.innerHTML = `<i class="fas fa-microphone mr-1"></i> ${audioSourceSelect.options[audioSourceSelect.selectedIndex].text}`;
|
327 |
+
}
|
328 |
+
|
329 |
+
// Stop visualization
|
330 |
+
function stopVisualization() {
|
331 |
+
if (animationId) {
|
332 |
+
cancelAnimationFrame(animationId);
|
333 |
+
animationId = null;
|
334 |
+
}
|
335 |
+
|
336 |
+
// Reset bars
|
337 |
+
bars.forEach(bar => {
|
338 |
+
bar.style.height = '0%';
|
339 |
+
bar.style.backgroundColor = '#3b82f6';
|
340 |
+
});
|
341 |
+
|
342 |
+
// Update device status
|
343 |
+
deviceStatus.innerHTML = '<i class="fas fa-microphone-slash mr-1"></i> No active input';
|
344 |
+
}
|
345 |
+
|
346 |
+
// Get audio constraints based on selected quality
|
347 |
+
function getAudioConstraints() {
|
348 |
+
const deviceId = audioSourceSelect.value;
|
349 |
+
const quality = audioQualitySelect.value;
|
350 |
+
|
351 |
+
let constraints = {
|
352 |
+
audio: {
|
353 |
+
deviceId: deviceId ? { exact: deviceId } : undefined,
|
354 |
+
echoCancellation: true,
|
355 |
+
noiseSuppression: true,
|
356 |
+
autoGainControl: true
|
357 |
+
}
|
358 |
+
};
|
359 |
+
|
360 |
+
// Adjust constraints based on quality
|
361 |
+
if (quality === 'high') {
|
362 |
+
constraints.audio.sampleRate = 48000;
|
363 |
+
constraints.audio.channelCount = 2;
|
364 |
+
constraints.audio.sampleSize = 16;
|
365 |
+
constraints.audio.bitrate = 256000;
|
366 |
+
} else if (quality === 'medium') {
|
367 |
+
constraints.audio.sampleRate = 44100;
|
368 |
+
constraints.audio.channelCount = 1;
|
369 |
+
constraints.audio.sampleSize = 16;
|
370 |
+
constraints.audio.bitrate = 128000;
|
371 |
+
} else { // low
|
372 |
+
constraints.audio.sampleRate = 22050;
|
373 |
+
constraints.audio.channelCount = 1;
|
374 |
+
constraints.audio.sampleSize = 8;
|
375 |
+
constraints.audio.bitrate = 64000;
|
376 |
+
}
|
377 |
+
|
378 |
+
return constraints;
|
379 |
+
}
|
380 |
+
|
381 |
+
// Initialize device selection
|
382 |
+
getAudioDevices().then(success => {
|
383 |
+
if (success) {
|
384 |
+
// When device selection changes, update the visualization
|
385 |
+
audioSourceSelect.addEventListener('change', async function() {
|
386 |
+
// Stop any existing visualization
|
387 |
+
stopVisualization();
|
388 |
+
if (currentStream) {
|
389 |
+
stopStream(currentStream);
|
390 |
+
}
|
391 |
+
|
392 |
+
// If a device is selected, start visualization
|
393 |
+
if (this.value) {
|
394 |
+
try {
|
395 |
+
const constraints = getAudioConstraints();
|
396 |
+
currentStream = await navigator.mediaDevices.getUserMedia(constraints);
|
397 |
+
visualizeAudio(currentStream);
|
398 |
+
} catch (error) {
|
399 |
+
console.error('Error accessing selected device:', error);
|
400 |
+
deviceStatus.innerHTML = '<i class="fas fa-exclamation-triangle mr-1"></i> Could not access selected device';
|
401 |
+
}
|
402 |
+
}
|
403 |
+
});
|
404 |
+
|
405 |
+
// Also update when quality changes
|
406 |
+
audioQualitySelect.addEventListener('change', function() {
|
407 |
+
if (audioSourceSelect.value) {
|
408 |
+
// Trigger change event to restart with new quality
|
409 |
+
audioSourceSelect.dispatchEvent(new Event('change'));
|
410 |
+
}
|
411 |
+
});
|
412 |
+
}
|
413 |
+
});
|
414 |
+
|
415 |
// Request permission to use microphone
|
416 |
recordBtn.addEventListener('click', async function() {
|
417 |
try {
|
418 |
+
const constraints = getAudioConstraints();
|
419 |
+
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
420 |
+
currentStream = stream;
|
421 |
+
|
422 |
+
// Stop visualization if it's running
|
423 |
+
stopVisualization();
|
424 |
|
425 |
mediaRecorder = new MediaRecorder(stream);
|
426 |
audioChunks = [];
|
|
|
442 |
|
443 |
// Add to recordings list
|
444 |
addRecordingToList(audioUrl);
|
445 |
+
|
446 |
+
// Restart visualization if a device was selected
|
447 |
+
if (audioSourceSelect.value) {
|
448 |
+
visualizeAudio(currentStream);
|
449 |
+
}
|
450 |
};
|
451 |
|
452 |
mediaRecorder.start(10); // Collect data every 10ms
|
|
|
480 |
mediaRecorder.stop();
|
481 |
|
482 |
// Stop all tracks in the stream
|
483 |
+
stopStream(currentStream);
|
484 |
|
485 |
// Clear timer
|
486 |
clearInterval(timerInterval);
|
|
|
552 |
<div>
|
553 |
<p class="font-medium">Recording ${recordingsList.children.length + 1}</p>
|
554 |
<p class="text-sm text-gray-500">${new Date().toLocaleString()}</p>
|
555 |
+
<p class="text-xs text-gray-400">${audioSourceSelect.options[audioSourceSelect.selectedIndex].text}</p>
|
556 |
</div>
|
557 |
</div>
|
558 |
<div class="flex gap-2">
|
prompts.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
website to record audio online and can download the result audio on any audio format
|
|
|
|
1 |
+
website to record audio online and can download the result audio on any audio format
|
2 |
+
now make it to user can select mix input from any device, like headset, mic etc
|