can you finish this https://github.com/kingoIII/Ruido
Browse files- README.md +7 -4
- components/footer.js +64 -0
- components/navbar.js +73 -0
- components/visualizer.js +183 -0
- index.html +83 -19
- script.js +135 -0
- style.css +40 -18
README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji: π
|
| 4 |
colorFrom: purple
|
| 5 |
-
colorTo:
|
|
|
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: EchoSphere Audio Visualizer π΅ π
|
|
|
|
| 3 |
colorFrom: purple
|
| 4 |
+
colorTo: red
|
| 5 |
+
emoji: π³
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://huggingface.co/deepsite).
|
components/footer.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class AudioFooter extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
:host {
|
| 7 |
+
display: block;
|
| 8 |
+
width: 100%;
|
| 9 |
+
background: rgba(17, 24, 39, 0.8);
|
| 10 |
+
backdrop-filter: blur(10px);
|
| 11 |
+
padding: 2rem 0;
|
| 12 |
+
margin-top: 4rem;
|
| 13 |
+
}
|
| 14 |
+
.footer-content {
|
| 15 |
+
max-width: 1200px;
|
| 16 |
+
margin: 0 auto;
|
| 17 |
+
padding: 0 2rem;
|
| 18 |
+
display: flex;
|
| 19 |
+
flex-direction: column;
|
| 20 |
+
align-items: center;
|
| 21 |
+
text-align: center;
|
| 22 |
+
}
|
| 23 |
+
.footer-links {
|
| 24 |
+
display: flex;
|
| 25 |
+
gap: 1.5rem;
|
| 26 |
+
margin-bottom: 1rem;
|
| 27 |
+
}
|
| 28 |
+
.footer-link {
|
| 29 |
+
color: rgba(156, 163, 175, 0.9);
|
| 30 |
+
text-decoration: none;
|
| 31 |
+
transition: color 0.2s;
|
| 32 |
+
}
|
| 33 |
+
.footer-link:hover {
|
| 34 |
+
color: white;
|
| 35 |
+
}
|
| 36 |
+
.copyright {
|
| 37 |
+
color: rgba(156, 163, 175, 0.7);
|
| 38 |
+
font-size: 0.875rem;
|
| 39 |
+
}
|
| 40 |
+
@media (max-width: 640px) {
|
| 41 |
+
.footer-links {
|
| 42 |
+
flex-direction: column;
|
| 43 |
+
gap: 0.75rem;
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
</style>
|
| 47 |
+
<div class="footer-content">
|
| 48 |
+
<div class="footer-links">
|
| 49 |
+
<a href="/" class="footer-link">Home</a>
|
| 50 |
+
<a href="https://github.com/kingoIII/Ruido1" target="_blank" rel="noopener noreferrer" class="footer-link">
|
| 51 |
+
GitHub
|
| 52 |
+
</a>
|
| 53 |
+
<a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API" target="_blank" rel="noopener noreferrer" class="footer-link">
|
| 54 |
+
Web Audio API
|
| 55 |
+
</a>
|
| 56 |
+
</div>
|
| 57 |
+
<div class="copyright">
|
| 58 |
+
© ${new Date().getFullYear()} EchoSphere Audio Visualizer
|
| 59 |
+
</div>
|
| 60 |
+
</div>
|
| 61 |
+
`;
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
customElements.define('audio-footer', AudioFooter);
|
components/navbar.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class AudioNavbar extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
:host {
|
| 7 |
+
display: block;
|
| 8 |
+
width: 100%;
|
| 9 |
+
background: rgba(17, 24, 39, 0.8);
|
| 10 |
+
backdrop-filter: blur(10px);
|
| 11 |
+
z-index: 50;
|
| 12 |
+
}
|
| 13 |
+
nav {
|
| 14 |
+
display: flex;
|
| 15 |
+
justify-content: space-between;
|
| 16 |
+
align-items: center;
|
| 17 |
+
max-width: 1200px;
|
| 18 |
+
margin: 0 auto;
|
| 19 |
+
padding: 1rem 2rem;
|
| 20 |
+
}
|
| 21 |
+
.nav-brand {
|
| 22 |
+
display: flex;
|
| 23 |
+
align-items: center;
|
| 24 |
+
font-weight: 700;
|
| 25 |
+
font-size: 1.25rem;
|
| 26 |
+
color: white;
|
| 27 |
+
text-decoration: none;
|
| 28 |
+
}
|
| 29 |
+
.nav-brand i {
|
| 30 |
+
margin-right: 0.5rem;
|
| 31 |
+
color: #818cf8;
|
| 32 |
+
}
|
| 33 |
+
.nav-links {
|
| 34 |
+
display: flex;
|
| 35 |
+
gap: 1.5rem;
|
| 36 |
+
}
|
| 37 |
+
.nav-link {
|
| 38 |
+
color: rgba(156, 163, 175, 0.9);
|
| 39 |
+
text-decoration: none;
|
| 40 |
+
transition: color 0.2s;
|
| 41 |
+
font-weight: 500;
|
| 42 |
+
}
|
| 43 |
+
.nav-link:hover {
|
| 44 |
+
color: white;
|
| 45 |
+
}
|
| 46 |
+
.github-icon:hover {
|
| 47 |
+
stroke: #818cf8;
|
| 48 |
+
}
|
| 49 |
+
@media (max-width: 640px) {
|
| 50 |
+
nav {
|
| 51 |
+
padding: 1rem;
|
| 52 |
+
}
|
| 53 |
+
.nav-links {
|
| 54 |
+
gap: 1rem;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
</style>
|
| 58 |
+
<nav>
|
| 59 |
+
<a href="/" class="nav-brand">
|
| 60 |
+
<i data-feather="music"></i>
|
| 61 |
+
EchoSphere
|
| 62 |
+
</a>
|
| 63 |
+
<div class="nav-links">
|
| 64 |
+
<a href="/" class="nav-link">Home</a>
|
| 65 |
+
<a href="https://github.com/kingoIII/Ruido1" target="_blank" rel="noopener noreferrer">
|
| 66 |
+
<i data-feather="github" class="github-icon w-5 h-5 text-gray-400 hover:text-indigo-400 transition"></i>
|
| 67 |
+
</a>
|
| 68 |
+
</div>
|
| 69 |
+
</nav>
|
| 70 |
+
`;
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
customElements.define('audio-navbar', AudioNavbar);
|
components/visualizer.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class AudioVisualizer extends HTMLElement {
|
| 2 |
+
constructor() {
|
| 3 |
+
super();
|
| 4 |
+
this.analyser = null;
|
| 5 |
+
this.animationId = null;
|
| 6 |
+
this.dataArray = null;
|
| 7 |
+
this.type = 'bars';
|
| 8 |
+
this.canvas = document.createElement('canvas');
|
| 9 |
+
this.ctx = this.canvas.getContext('2d');
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
static get observedAttributes() {
|
| 13 |
+
return ['type'];
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
attributeChangedCallback(name, oldValue, newValue) {
|
| 17 |
+
if (name === 'type') {
|
| 18 |
+
this.type = newValue;
|
| 19 |
+
if (this.animationId) {
|
| 20 |
+
cancelAnimationFrame(this.animationId);
|
| 21 |
+
this.startVisualization();
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
connectedCallback() {
|
| 27 |
+
this.attachShadow({ mode: 'open' });
|
| 28 |
+
|
| 29 |
+
// Set canvas dimensions to match the component
|
| 30 |
+
this.canvas.width = this.clientWidth;
|
| 31 |
+
this.canvas.height = this.clientHeight;
|
| 32 |
+
|
| 33 |
+
this.shadowRoot.appendChild(this.canvas);
|
| 34 |
+
|
| 35 |
+
// Initialize the data array with the correct size
|
| 36 |
+
if (this.analyser) {
|
| 37 |
+
this.dataArray = new Uint8Array(this.analyser.frequencyBinCount);
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
setAnalyser(analyser) {
|
| 42 |
+
this.analyser = analyser;
|
| 43 |
+
if (this.analyser) {
|
| 44 |
+
this.dataArray = new Uint8Array(this.analyser.frequencyBinCount);
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
startVisualization() {
|
| 49 |
+
if (!this.analyser) return;
|
| 50 |
+
|
| 51 |
+
const draw = () => {
|
| 52 |
+
this.analyser.getByteFrequencyData(this.dataArray);
|
| 53 |
+
this.clearCanvas();
|
| 54 |
+
|
| 55 |
+
switch(this.type) {
|
| 56 |
+
case 'bars':
|
| 57 |
+
this.drawBars();
|
| 58 |
+
break;
|
| 59 |
+
case 'wave':
|
| 60 |
+
this.drawWave();
|
| 61 |
+
break;
|
| 62 |
+
case 'circle':
|
| 63 |
+
this.drawCircle();
|
| 64 |
+
break;
|
| 65 |
+
default:
|
| 66 |
+
this.drawBars();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
this.animationId = requestAnimationFrame(draw);
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
draw();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
stopVisualization() {
|
| 76 |
+
if (this.animationId) {
|
| 77 |
+
cancelAnimationFrame(this.animationId);
|
| 78 |
+
this.animationId = null;
|
| 79 |
+
this.clearCanvas();
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
clearCanvas() {
|
| 84 |
+
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
drawBars() {
|
| 88 |
+
const width = this.canvas.width;
|
| 89 |
+
const height = this.canvas.height;
|
| 90 |
+
const barWidth = width / this.dataArray.length;
|
| 91 |
+
const gradient = this.ctx.createLinearGradient(0, 0, 0, height);
|
| 92 |
+
gradient.addColorStop(0, '#4f46e5');
|
| 93 |
+
gradient.addColorStop(1, '#c026d3');
|
| 94 |
+
|
| 95 |
+
this.ctx.fillStyle = gradient;
|
| 96 |
+
|
| 97 |
+
for (let i = 0; i < this.dataArray.length; i++) {
|
| 98 |
+
const barHeight = (this.dataArray[i] / 255) * height;
|
| 99 |
+
const x = i * barWidth;
|
| 100 |
+
const y = height - barHeight;
|
| 101 |
+
|
| 102 |
+
// Add some rounded corners to the bars
|
| 103 |
+
this.ctx.beginPath();
|
| 104 |
+
this.ctx.moveTo(x + barWidth / 2, y);
|
| 105 |
+
this.ctx.arcTo(x + barWidth, y, x + barWidth, y + barHeight, 2);
|
| 106 |
+
this.ctx.arcTo(x + barWidth, y + barHeight, x, y + barHeight, 2);
|
| 107 |
+
this.ctx.arcTo(x, y + barHeight, x, y, 2);
|
| 108 |
+
this.ctx.arcTo(x, y, x + barWidth / 2, y, 2);
|
| 109 |
+
this.ctx.closePath();
|
| 110 |
+
this.ctx.fill();
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
drawWave() {
|
| 115 |
+
const width = this.canvas.width;
|
| 116 |
+
const height = this.canvas.height;
|
| 117 |
+
const sliceWidth = width / this.dataArray.length;
|
| 118 |
+
|
| 119 |
+
this.ctx.lineWidth = 2;
|
| 120 |
+
this.ctx.strokeStyle = '#818cf8';
|
| 121 |
+
this.ctx.beginPath();
|
| 122 |
+
|
| 123 |
+
let x = 0;
|
| 124 |
+
for (let i = 0; i < this.dataArray.length; i++) {
|
| 125 |
+
const v = this.dataArray[i] / 255;
|
| 126 |
+
const y = v * height / 2;
|
| 127 |
+
|
| 128 |
+
if (i === 0) {
|
| 129 |
+
this.ctx.moveTo(x, y);
|
| 130 |
+
} else {
|
| 131 |
+
this.ctx.lineTo(x, y);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
x += sliceWidth;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
this.ctx.lineTo(width, height / 2);
|
| 138 |
+
this.ctx.stroke();
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
drawCircle() {
|
| 142 |
+
const centerX = this.canvas.width / 2;
|
| 143 |
+
const centerY = this.canvas.height / 2;
|
| 144 |
+
const radius = Math.min(this.canvas.width, this.canvas.height) * 0.4;
|
| 145 |
+
|
| 146 |
+
this.ctx.lineWidth = 2;
|
| 147 |
+
|
| 148 |
+
for (let i = 0; i < this.dataArray.length; i++) {
|
| 149 |
+
const amplitude = this.dataArray[i] / 255;
|
| 150 |
+
const angle = (i / this.dataArray.length) * Math.PI * 2;
|
| 151 |
+
const pointRadius = radius + (amplitude * radius * 0.5);
|
| 152 |
+
|
| 153 |
+
const x = centerX + Math.cos(angle) * pointRadius;
|
| 154 |
+
const y = centerY + Math.sin(angle) * pointRadius;
|
| 155 |
+
|
| 156 |
+
// Gradient color based on frequency
|
| 157 |
+
const gradient = this.ctx.createRadialGradient(x, y, 0, x, y, 5);
|
| 158 |
+
gradient.addColorStop(0, '#8b5cf6');
|
| 159 |
+
gradient.addColorStop(1, '#3b82f6');
|
| 160 |
+
|
| 161 |
+
this.ctx.beginPath();
|
| 162 |
+
this.ctx.arc(x, y, 3, 0, Math.PI * 2);
|
| 163 |
+
this.ctx.fillStyle = gradient;
|
| 164 |
+
this.ctx.fill();
|
| 165 |
+
|
| 166 |
+
// Draw connecting lines for a more dynamic effect
|
| 167 |
+
if (i > 0) {
|
| 168 |
+
const prevAngle = ((i - 1) / this.dataArray.length) * Math.PI * 2;
|
| 169 |
+
const prevAmplitude = this.dataArray[i - 1] / 255;
|
| 170 |
+
const prevPointRadius = radius + (prevAmplitude * radius * 0.5);
|
| 171 |
+
const prevX = centerX + Math.cos(prevAngle) * prevPointRadius;
|
| 172 |
+
const prevY = centerY + Math.sin(prevAngle) * prevPointRadius;
|
| 173 |
+
|
| 174 |
+
this.ctx.beginPath();
|
| 175 |
+
this.ctx.moveTo(prevX, prevY);
|
| 176 |
+
this.ctx.lineTo(x, y);
|
| 177 |
+
this.ctx.strokeStyle = `rgba(139, 92, 246, ${0.5 + amplitude * 0.5})`;
|
| 178 |
+
this.ctx.stroke();
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
}
|
| 183 |
+
customElements.define('audio-visualizer', AudioVisualizer);
|
index.html
CHANGED
|
@@ -1,19 +1,83 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en" class="dark">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>EchoSphere Audio Visualizer</title>
|
| 7 |
+
<link rel="stylesheet" href="style.css">
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 10 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 11 |
+
</head>
|
| 12 |
+
<body class="bg-gray-900 text-gray-100 min-h-screen">
|
| 13 |
+
<audio-navbar></audio-navbar>
|
| 14 |
+
|
| 15 |
+
<main class="container mx-auto px-4 py-8">
|
| 16 |
+
<div class="text-center mb-12">
|
| 17 |
+
<h1 class="text-4xl md:text-6xl font-bold mb-4 bg-clip-text text-transparent bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500">
|
| 18 |
+
EchoSphere
|
| 19 |
+
</h1>
|
| 20 |
+
<p class="text-xl text-gray-400 max-w-2xl mx-auto">
|
| 21 |
+
A mesmerizing audio visualization experience that transforms sound into vibrant waveforms
|
| 22 |
+
</p>
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-12">
|
| 26 |
+
<div class="bg-gray-800 rounded-2xl p-6 shadow-xl">
|
| 27 |
+
<h2 class="text-2xl font-semibold mb-4">π€ Live Audio Input</h2>
|
| 28 |
+
<p class="text-gray-400 mb-6">Connect your microphone or audio device and watch the visualization respond in real-time.</p>
|
| 29 |
+
<button id="startAudio" class="bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-2 px-6 rounded-full transition">
|
| 30 |
+
Start Listening
|
| 31 |
+
</button>
|
| 32 |
+
<div class="mt-8">
|
| 33 |
+
<audio-visualizer type="circle"></audio-visualizer>
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
<div class="bg-gray-800 rounded-2xl p-6 shadow-xl">
|
| 38 |
+
<h2 class="text-2xl font-semibold mb-4">π΅ Audio File Upload</h2>
|
| 39 |
+
<p class="text-gray-400 mb-6">Select an audio file from your device to visualize your favorite tracks.</p>
|
| 40 |
+
<div class="mb-4">
|
| 41 |
+
<input type="file" id="audioUpload" accept="audio/*" class="hidden">
|
| 42 |
+
<label for="audioUpload" class="cursor-pointer bg-purple-600 hover:bg-purple-700 text-white font-medium py-2 px-6 rounded-full inline-block transition">
|
| 43 |
+
Choose File
|
| 44 |
+
</label>
|
| 45 |
+
<span id="fileName" class="ml-4 text-gray-400">No file selected</span>
|
| 46 |
+
</div>
|
| 47 |
+
<div class="mt-8">
|
| 48 |
+
<audio-visualizer type="bars"></audio-visualizer>
|
| 49 |
+
</div>
|
| 50 |
+
</div>
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
<div class="bg-gray-800 rounded-2xl p-6 shadow-xl mb-12">
|
| 54 |
+
<h2 class="text-2xl font-semibold mb-6">π¨ Visualization Styles</h2>
|
| 55 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 56 |
+
<button class="visualizer-style bg-gray-700 hover:bg-gray-600 rounded-lg p-4 transition" data-type="bars">
|
| 57 |
+
<i data-feather="bar-chart-2" class="w-8 h-8 mb-2"></i>
|
| 58 |
+
<span>Frequency Bars</span>
|
| 59 |
+
</button>
|
| 60 |
+
<button class="visualizer-style bg-gray-700 hover:bg-gray-600 rounded-lg p-4 transition" data-type="wave">
|
| 61 |
+
<i data-feather="activity" class="w-8 h-8 mb-2"></i>
|
| 62 |
+
<span>Waveform</span>
|
| 63 |
+
</button>
|
| 64 |
+
<button class="visualizer-style bg-gray-700 hover:bg-gray-600 rounded-lg p-4 transition" data-type="circle">
|
| 65 |
+
<i data-feather="circle" class="w-8 h-8 mb-2"></i>
|
| 66 |
+
<span>Circle Spectrum</span>
|
| 67 |
+
</button>
|
| 68 |
+
</div>
|
| 69 |
+
</div>
|
| 70 |
+
</main>
|
| 71 |
+
|
| 72 |
+
<audio-footer></audio-footer>
|
| 73 |
+
|
| 74 |
+
<script src="components/navbar.js"></script>
|
| 75 |
+
<script src="components/footer.js"></script>
|
| 76 |
+
<script src="components/visualizer.js"></script>
|
| 77 |
+
<script src="script.js"></script>
|
| 78 |
+
<script>
|
| 79 |
+
feather.replace();
|
| 80 |
+
</script>
|
| 81 |
+
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 82 |
+
</body>
|
| 83 |
+
</html>
|
script.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 2 |
+
// Audio context setup
|
| 3 |
+
let audioContext;
|
| 4 |
+
let analyser;
|
| 5 |
+
let audioSource;
|
| 6 |
+
let isPlaying = false;
|
| 7 |
+
let activeVisualizerType = 'bars';
|
| 8 |
+
|
| 9 |
+
// DOM elements
|
| 10 |
+
const startAudioBtn = document.getElementById('startAudio');
|
| 11 |
+
const audioUpload = document.getElementById('audioUpload');
|
| 12 |
+
const fileNameSpan = document.getElementById('fileName');
|
| 13 |
+
const visualizerStyles = document.querySelectorAll('.visualizer-style');
|
| 14 |
+
|
| 15 |
+
// Initialize audio context on user interaction
|
| 16 |
+
startAudioBtn.addEventListener('click', toggleAudioInput);
|
| 17 |
+
audioUpload.addEventListener('change', handleFileUpload);
|
| 18 |
+
|
| 19 |
+
// Visualizer style selector
|
| 20 |
+
visualizerStyles.forEach(style => {
|
| 21 |
+
style.addEventListener('click', () => {
|
| 22 |
+
visualizerStyles.forEach(s => s.classList.remove('ring-2', 'ring-indigo-500'));
|
| 23 |
+
style.classList.add('ring-2', 'ring-indigo-500');
|
| 24 |
+
activeVisualizerType = style.dataset.type;
|
| 25 |
+
document.querySelectorAll('audio-visualizer').forEach(viz => {
|
| 26 |
+
viz.setAttribute('type', activeVisualizerType);
|
| 27 |
+
});
|
| 28 |
+
});
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
// Set default visualizer style
|
| 32 |
+
visualizerStyles[0].click();
|
| 33 |
+
|
| 34 |
+
async function toggleAudioInput() {
|
| 35 |
+
try {
|
| 36 |
+
if (!isPlaying) {
|
| 37 |
+
await setupAudioContext();
|
| 38 |
+
startAudioBtn.textContent = 'Stop Listening';
|
| 39 |
+
startAudioBtn.classList.remove('bg-indigo-600', 'hover:bg-indigo-700');
|
| 40 |
+
startAudioBtn.classList.add('bg-pink-600', 'hover:bg-pink-700', 'pulse');
|
| 41 |
+
isPlaying = true;
|
| 42 |
+
} else {
|
| 43 |
+
stopAudio();
|
| 44 |
+
startAudioBtn.textContent = 'Start Listening';
|
| 45 |
+
startAudioBtn.classList.remove('bg-pink-600', 'hover:bg-pink-700', 'pulse');
|
| 46 |
+
startAudioBtn.classList.add('bg-indigo-600', 'hover:bg-indigo-700');
|
| 47 |
+
isPlaying = false;
|
| 48 |
+
}
|
| 49 |
+
} catch (error) {
|
| 50 |
+
console.error('Error accessing microphone:', error);
|
| 51 |
+
alert('Could not access microphone. Please check permissions.');
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
async function setupAudioContext() {
|
| 56 |
+
if (!audioContext) {
|
| 57 |
+
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
| 58 |
+
analyser = audioContext.createAnalyser();
|
| 59 |
+
analyser.fftSize = 256;
|
| 60 |
+
|
| 61 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 62 |
+
audioSource = audioContext.createMediaStreamSource(stream);
|
| 63 |
+
audioSource.connect(analyser);
|
| 64 |
+
|
| 65 |
+
// Connect all visualizers to this analyser
|
| 66 |
+
document.querySelectorAll('audio-visualizer').forEach(viz => {
|
| 67 |
+
viz.setAnalyser(analyser);
|
| 68 |
+
viz.startVisualization();
|
| 69 |
+
});
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function stopAudio() {
|
| 74 |
+
if (audioSource && audioSource.mediaStream) {
|
| 75 |
+
audioSource.mediaStream.getTracks().forEach(track => track.stop());
|
| 76 |
+
}
|
| 77 |
+
if (audioContext) {
|
| 78 |
+
document.querySelectorAll('audio-visualizer').forEach(viz => {
|
| 79 |
+
viz.stopVisualization();
|
| 80 |
+
});
|
| 81 |
+
// Don't close the context to avoid re-creating it
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
function handleFileUpload(e) {
|
| 86 |
+
const file = e.target.files[0];
|
| 87 |
+
if (!file) return;
|
| 88 |
+
|
| 89 |
+
fileNameSpan.textContent = file.name;
|
| 90 |
+
|
| 91 |
+
if (audioContext) {
|
| 92 |
+
stopAudio();
|
| 93 |
+
isPlaying = false;
|
| 94 |
+
startAudioBtn.textContent = 'Start Listening';
|
| 95 |
+
startAudioBtn.classList.remove('bg-pink-600', 'hover:bg-pink-700', 'pulse');
|
| 96 |
+
startAudioBtn.classList.add('bg-indigo-600', 'hover:bg-indigo-700');
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
const reader = new FileReader();
|
| 100 |
+
reader.onload = function(e) {
|
| 101 |
+
const arrayBuffer = e.target.result;
|
| 102 |
+
processAudioFile(arrayBuffer);
|
| 103 |
+
};
|
| 104 |
+
reader.readAsArrayBuffer(file);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
function processAudioFile(arrayBuffer) {
|
| 108 |
+
if (!audioContext) {
|
| 109 |
+
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
| 110 |
+
analyser = audioContext.createAnalyser();
|
| 111 |
+
analyser.fftSize = 256;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
audioContext.decodeAudioData(arrayBuffer, function(buffer) {
|
| 115 |
+
if (audioSource) {
|
| 116 |
+
audioSource.disconnect();
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
audioSource = audioContext.createBufferSource();
|
| 120 |
+
audioSource.buffer = buffer;
|
| 121 |
+
audioSource.connect(analyser);
|
| 122 |
+
audioSource.connect(audioContext.destination);
|
| 123 |
+
audioSource.start();
|
| 124 |
+
|
| 125 |
+
isPlaying = true;
|
| 126 |
+
document.querySelectorAll('audio-visualizer').forEach(viz => {
|
| 127 |
+
viz.setAnalyser(analyser);
|
| 128 |
+
viz.startVisualization();
|
| 129 |
+
});
|
| 130 |
+
}, function(e) {
|
| 131 |
+
console.error('Error decoding audio file:', e);
|
| 132 |
+
alert('Error loading audio file. Please try another file.');
|
| 133 |
+
});
|
| 134 |
+
}
|
| 135 |
+
});
|
style.css
CHANGED
|
@@ -1,28 +1,50 @@
|
|
|
|
|
| 1 |
body {
|
| 2 |
-
|
| 3 |
-
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
| 4 |
}
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
-
.
|
| 19 |
-
|
| 20 |
-
margin: 0 auto;
|
| 21 |
-
padding: 16px;
|
| 22 |
-
border: 1px solid lightgray;
|
| 23 |
-
border-radius: 16px;
|
| 24 |
}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Base styles */
|
| 2 |
body {
|
| 3 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
|
|
| 4 |
}
|
| 5 |
|
| 6 |
+
/* Visualizer canvas styles */
|
| 7 |
+
audio-visualizer {
|
| 8 |
+
display: block;
|
| 9 |
+
width: 100%;
|
| 10 |
+
height: 300px;
|
| 11 |
+
background: linear-gradient(135deg, rgba(30, 27, 75, 0.5) 0%, rgba(11, 11, 25, 0.7) 100%);
|
| 12 |
+
border-radius: 12px;
|
| 13 |
+
transition: all 0.3s ease;
|
| 14 |
}
|
| 15 |
|
| 16 |
+
/* Pulse animation for active buttons */
|
| 17 |
+
@keyframes pulse {
|
| 18 |
+
0% {
|
| 19 |
+
box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7);
|
| 20 |
+
}
|
| 21 |
+
70% {
|
| 22 |
+
box-shadow: 0 0 0 10px rgba(99, 102, 241, 0);
|
| 23 |
+
}
|
| 24 |
+
100% {
|
| 25 |
+
box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
|
| 26 |
+
}
|
| 27 |
}
|
| 28 |
|
| 29 |
+
.pulse {
|
| 30 |
+
animation: pulse 1.5s infinite;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
|
| 33 |
+
/* Custom scrollbar */
|
| 34 |
+
::-webkit-scrollbar {
|
| 35 |
+
width: 8px;
|
| 36 |
+
height: 8px;
|
| 37 |
}
|
| 38 |
+
|
| 39 |
+
::-webkit-scrollbar-track {
|
| 40 |
+
background: rgba(17, 24, 39, 0.5);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
::-webkit-scrollbar-thumb {
|
| 44 |
+
background: rgba(79, 70, 229, 0.7);
|
| 45 |
+
border-radius: 4px;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
::-webkit-scrollbar-thumb:hover {
|
| 49 |
+
background: rgba(99, 102, 241, 0.9);
|
| 50 |
+
}
|