Spaces:
Running
Running
Add 2 files
Browse files- index.html +221 -2
- prompts.txt +2 -1
index.html
CHANGED
|
@@ -54,6 +54,10 @@
|
|
| 54 |
background: linear-gradient(to top, rgba(0, 180, 219, 0.1), transparent);
|
| 55 |
clip-path: polygon(0% 100%, 100% 100%, 100% 0%, 0% 0%);
|
| 56 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
</style>
|
| 58 |
</head>
|
| 59 |
<body class="bg-gray-900 text-white min-h-screen flex flex-col items-center justify-center p-4">
|
|
@@ -76,11 +80,13 @@
|
|
| 76 |
</div>
|
| 77 |
<div class="flex-1">
|
| 78 |
<button id="playButton" class="bg-gradient-to-r from-pink-500 to-purple-500 hover:from-pink-600 hover:to-purple-600 text-white font-bold py-3 px-6 rounded-lg w-full flex items-center justify-center transition-all duration-300 shadow-lg hover:shadow-xl">
|
| 79 |
-
<i class="fas fa-play mr-2"></i> Play
|
| 80 |
</button>
|
| 81 |
</div>
|
| 82 |
</div>
|
| 83 |
|
|
|
|
|
|
|
| 84 |
<div class="mt-8 grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 85 |
<div class="bg-gray-800 p-4 rounded-lg">
|
| 86 |
<h3 class="text-cyan-400 font-semibold mb-2"><i class="fas fa-sliders-h mr-2"></i>Controls</h3>
|
|
@@ -134,6 +140,7 @@
|
|
| 134 |
const audioWave = document.getElementById('audioWave');
|
| 135 |
const playButton = document.getElementById('playButton');
|
| 136 |
const audioUpload = document.getElementById('audioUpload');
|
|
|
|
| 137 |
const statusElement = document.getElementById('status');
|
| 138 |
const beatStatusElement = document.getElementById('beatStatus');
|
| 139 |
const volumeLevelElement = document.getElementById('volumeLevel');
|
|
@@ -154,5 +161,217 @@
|
|
| 154 |
const barWidth = containerWidth / barCount;
|
| 155 |
|
| 156 |
for (let i = 0; i < barCount; i++) {
|
| 157 |
-
const bar = document.createElement('div
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
</html>
|
|
|
|
| 54 |
background: linear-gradient(to top, rgba(0, 180, 219, 0.1), transparent);
|
| 55 |
clip-path: polygon(0% 100%, 100% 100%, 100% 0%, 0% 0%);
|
| 56 |
}
|
| 57 |
+
|
| 58 |
+
#audioPlayer {
|
| 59 |
+
display: none;
|
| 60 |
+
}
|
| 61 |
</style>
|
| 62 |
</head>
|
| 63 |
<body class="bg-gray-900 text-white min-h-screen flex flex-col items-center justify-center p-4">
|
|
|
|
| 80 |
</div>
|
| 81 |
<div class="flex-1">
|
| 82 |
<button id="playButton" class="bg-gradient-to-r from-pink-500 to-purple-500 hover:from-pink-600 hover:to-purple-600 text-white font-bold py-3 px-6 rounded-lg w-full flex items-center justify-center transition-all duration-300 shadow-lg hover:shadow-xl">
|
| 83 |
+
<i class="fas fa-play mr-2"></i> Play
|
| 84 |
</button>
|
| 85 |
</div>
|
| 86 |
</div>
|
| 87 |
|
| 88 |
+
<audio id="audioPlayer" controls></audio>
|
| 89 |
+
|
| 90 |
<div class="mt-8 grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 91 |
<div class="bg-gray-800 p-4 rounded-lg">
|
| 92 |
<h3 class="text-cyan-400 font-semibold mb-2"><i class="fas fa-sliders-h mr-2"></i>Controls</h3>
|
|
|
|
| 140 |
const audioWave = document.getElementById('audioWave');
|
| 141 |
const playButton = document.getElementById('playButton');
|
| 142 |
const audioUpload = document.getElementById('audioUpload');
|
| 143 |
+
const audioPlayer = document.getElementById('audioPlayer');
|
| 144 |
const statusElement = document.getElementById('status');
|
| 145 |
const beatStatusElement = document.getElementById('beatStatus');
|
| 146 |
const volumeLevelElement = document.getElementById('volumeLevel');
|
|
|
|
| 161 |
const barWidth = containerWidth / barCount;
|
| 162 |
|
| 163 |
for (let i = 0; i < barCount; i++) {
|
| 164 |
+
const bar = document.createElement('div');
|
| 165 |
+
bar.className = 'bar';
|
| 166 |
+
bar.style.left = `${i * barWidth}px`;
|
| 167 |
+
bar.style.height = '0px';
|
| 168 |
+
visualizer.appendChild(bar);
|
| 169 |
+
bars.push(bar);
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
createBars();
|
| 174 |
+
|
| 175 |
+
// Handle file upload
|
| 176 |
+
audioUpload.addEventListener('change', (e) => {
|
| 177 |
+
const file = e.target.files[0];
|
| 178 |
+
if (!file) return;
|
| 179 |
+
|
| 180 |
+
const fileURL = URL.createObjectURL(file);
|
| 181 |
+
audioPlayer.src = fileURL;
|
| 182 |
+
statusElement.textContent = 'Ready to play';
|
| 183 |
+
statusElement.className = 'text-green-400';
|
| 184 |
+
|
| 185 |
+
// Reset visualization
|
| 186 |
+
if (isPlaying) {
|
| 187 |
+
stopAudio();
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// Setup audio when ready
|
| 191 |
+
audioPlayer.oncanplaythrough = () => {
|
| 192 |
+
setupAudio();
|
| 193 |
+
};
|
| 194 |
+
});
|
| 195 |
+
|
| 196 |
+
// Play button click
|
| 197 |
+
playButton.addEventListener('click', () => {
|
| 198 |
+
if (!audioPlayer.src) {
|
| 199 |
+
statusElement.textContent = 'No audio selected';
|
| 200 |
+
statusElement.className = 'text-red-400';
|
| 201 |
+
return;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
if (isPlaying) {
|
| 205 |
+
stopAudio();
|
| 206 |
+
playButton.innerHTML = '<i class="fas fa-play mr-2"></i> Play';
|
| 207 |
+
} else {
|
| 208 |
+
startAudio();
|
| 209 |
+
playButton.innerHTML = '<i class="fas fa-pause mr-2"></i> Pause';
|
| 210 |
+
}
|
| 211 |
+
});
|
| 212 |
+
|
| 213 |
+
// Setup audio context and analyzer
|
| 214 |
+
function setupAudio() {
|
| 215 |
+
if (audioSource) {
|
| 216 |
+
audioSource.disconnect();
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
analyser = audioContext.createAnalyser();
|
| 220 |
+
analyser.fftSize = 2048;
|
| 221 |
+
|
| 222 |
+
audioSource = audioContext.createMediaElementSource(audioPlayer);
|
| 223 |
+
audioSource.connect(analyser);
|
| 224 |
+
analyser.connect(audioContext.destination);
|
| 225 |
+
|
| 226 |
+
const bufferLength = analyser.frequencyBinCount;
|
| 227 |
+
dataArray = new Uint8Array(bufferLength);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
// Start audio playback and visualization
|
| 231 |
+
function startAudio() {
|
| 232 |
+
if (audioContext.state === 'suspended') {
|
| 233 |
+
audioContext.resume();
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
audioPlayer.play();
|
| 237 |
+
isPlaying = true;
|
| 238 |
+
statusElement.textContent = 'Playing';
|
| 239 |
+
statusElement.className = 'text-green-400';
|
| 240 |
+
|
| 241 |
+
// Start visualization
|
| 242 |
+
visualize();
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
// Stop audio playback and visualization
|
| 246 |
+
function stopAudio() {
|
| 247 |
+
audioPlayer.pause();
|
| 248 |
+
isPlaying = false;
|
| 249 |
+
statusElement.textContent = 'Paused';
|
| 250 |
+
statusElement.className = 'text-yellow-400';
|
| 251 |
+
|
| 252 |
+
// Stop visualization
|
| 253 |
+
cancelAnimationFrame(animationId);
|
| 254 |
+
|
| 255 |
+
// Reset bars
|
| 256 |
+
bars.forEach(bar => {
|
| 257 |
+
bar.style.height = '0px';
|
| 258 |
+
});
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// Beat detection function
|
| 262 |
+
function detectBeat(level) {
|
| 263 |
+
if (level > beatCutOff && level > beatThreshold) {
|
| 264 |
+
// Beat detected
|
| 265 |
+
beatCutOff = level * 1.1;
|
| 266 |
+
lastBeatTime = Date.now();
|
| 267 |
+
|
| 268 |
+
// Create beat circle
|
| 269 |
+
createBeatCircle();
|
| 270 |
+
|
| 271 |
+
return true;
|
| 272 |
+
} else {
|
| 273 |
+
// Decay beat cutoff
|
| 274 |
+
if (Date.now() - lastBeatTime > beatHoldTime) {
|
| 275 |
+
beatCutOff *= beatDecayRate;
|
| 276 |
+
beatCutOff = Math.max(beatCutOff, beatThreshold);
|
| 277 |
+
}
|
| 278 |
+
return false;
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
// Create a beat circle at random position
|
| 283 |
+
function createBeatCircle() {
|
| 284 |
+
const circle = document.createElement('div');
|
| 285 |
+
circle.className = 'beat-circle pulse';
|
| 286 |
+
|
| 287 |
+
// Random position
|
| 288 |
+
const x = Math.random() * visualizer.clientWidth;
|
| 289 |
+
const y = Math.random() * visualizer.clientHeight * 0.7;
|
| 290 |
+
const size = 30 + Math.random() * 70;
|
| 291 |
+
|
| 292 |
+
circle.style.left = `${x}px`;
|
| 293 |
+
circle.style.top = `${y}px`;
|
| 294 |
+
circle.style.width = `${size}px`;
|
| 295 |
+
circle.style.height = `${size}px`;
|
| 296 |
+
|
| 297 |
+
visualizer.appendChild(circle);
|
| 298 |
+
|
| 299 |
+
// Remove after animation
|
| 300 |
+
setTimeout(() => {
|
| 301 |
+
circle.remove();
|
| 302 |
+
}, 500);
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
// Main visualization function
|
| 306 |
+
function visualize() {
|
| 307 |
+
animationId = requestAnimationFrame(visualize);
|
| 308 |
+
|
| 309 |
+
analyser.getByteFrequencyData(dataArray);
|
| 310 |
+
|
| 311 |
+
// Calculate average volume
|
| 312 |
+
let sum = 0;
|
| 313 |
+
for (let i = 0; i < dataArray.length; i++) {
|
| 314 |
+
sum += dataArray[i];
|
| 315 |
+
}
|
| 316 |
+
const average = sum / dataArray.length;
|
| 317 |
+
const volumePercent = Math.min(Math.round((average / 255) * 100), 100);
|
| 318 |
+
volumeLevelElement.textContent = volumePercent;
|
| 319 |
+
|
| 320 |
+
// Check for beat
|
| 321 |
+
if (detectBeat(average * sensitivity)) {
|
| 322 |
+
beatStatusElement.textContent = 'Beat detected!';
|
| 323 |
+
beatStatusElement.className = 'text-pink-400 animate-pulse';
|
| 324 |
+
setTimeout(() => {
|
| 325 |
+
beatStatusElement.textContent = 'Listening...';
|
| 326 |
+
beatStatusElement.className = 'text-cyan-400';
|
| 327 |
+
}, 200);
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
// Update bars
|
| 331 |
+
const barGroupSize = Math.floor(dataArray.length / barCount);
|
| 332 |
+
for (let i = 0; i < barCount; i++) {
|
| 333 |
+
const start = i * barGroupSize;
|
| 334 |
+
let sum = 0;
|
| 335 |
+
|
| 336 |
+
for (let j = start; j < start + barGroupSize; j++) {
|
| 337 |
+
sum += dataArray[j];
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
const average = sum / barGroupSize;
|
| 341 |
+
const height = (average / 255) * visualizer.clientHeight * 1.2;
|
| 342 |
+
|
| 343 |
+
bars[i].style.height = `${height}px`;
|
| 344 |
+
bars[i].style.opacity = `${0.2 + (height / visualizer.clientHeight) * 0.8}`;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
// Update audio wave
|
| 348 |
+
analyser.getByteTimeDomainData(dataArray);
|
| 349 |
+
let wavePath = 'path(\'M0 ' + (visualizer.clientHeight / 2) + ' ';
|
| 350 |
+
for (let i = 0; i < dataArray.length; i++) {
|
| 351 |
+
const x = (i / dataArray.length) * visualizer.clientWidth;
|
| 352 |
+
const y = (dataArray[i] / 255) * visualizer.clientHeight;
|
| 353 |
+
wavePath += 'L' + x + ' ' + y + ' ';
|
| 354 |
+
}
|
| 355 |
+
wavePath += 'L' + visualizer.clientWidth + ' ' + (visualizer.clientHeight / 2) + ' Z\')';
|
| 356 |
+
audioWave.style.clipPath = wavePath;
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
// Handle sensitivity change
|
| 360 |
+
sensitivityInput.addEventListener('input', () => {
|
| 361 |
+
sensitivity = parseFloat(sensitivityInput.value);
|
| 362 |
+
});
|
| 363 |
+
|
| 364 |
+
// Handle bar count change
|
| 365 |
+
barCountInput.addEventListener('input', () => {
|
| 366 |
+
barCount = parseInt(barCountInput.value);
|
| 367 |
+
createBars();
|
| 368 |
+
});
|
| 369 |
+
|
| 370 |
+
// Handle window resize
|
| 371 |
+
window.addEventListener('resize', () => {
|
| 372 |
+
createBars();
|
| 373 |
+
});
|
| 374 |
+
});
|
| 375 |
+
</script>
|
| 376 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=omar1232/audio-react-visualizer" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 377 |
</html>
|
prompts.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
make audio viylation reacts to the beat and audio
|
|
|
|
|
|
| 1 |
+
make audio viylation reacts to the beat and audio
|
| 2 |
+
the audio cant be uploaded
|