Fixed logo spin + added automatic subtitle that maybe works

This commit is contained in:
AlacrisDevs
2026-02-16 20:19:55 +02:00
parent 53b0457857
commit 3e7c11be8a
4 changed files with 48 additions and 6 deletions

4
package-lock.json generated
View File

@@ -5,7 +5,7 @@
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ncs-visualizer", "name": "audio-visualizer",
"version": "1.0.0", "version": "1.0.0",
"devDependencies": { "devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.1.0", "@sveltejs/vite-plugin-svelte": "^3.1.0",
@@ -1299,4 +1299,4 @@
} }
} }
} }
} }

View File

@@ -31,6 +31,7 @@
glowIntensity: 0.6, glowIntensity: 0.6,
logoSpin: false, logoSpin: false,
logoSpinSpeed: 5, logoSpinSpeed: 5,
autoSubtitle: false,
titlePosition: "top", titlePosition: "top",
}; };
@@ -71,7 +72,9 @@
let glowIntensity = saved.glowIntensity; let glowIntensity = saved.glowIntensity;
let logoSpin = saved.logoSpin; let logoSpin = saved.logoSpin;
let logoSpinSpeed = saved.logoSpinSpeed; let logoSpinSpeed = saved.logoSpinSpeed;
let autoSubtitle = saved.autoSubtitle;
let titlePosition = saved.titlePosition; let titlePosition = saved.titlePosition;
let capturedTrackLabel = "";
let visualizerComponent; let visualizerComponent;
let toggleHidden = false; let toggleHidden = false;
let hideTimer; let hideTimer;
@@ -99,6 +102,10 @@
clearTimeout(hideTimer); clearTimeout(hideTimer);
} }
$: if (autoSubtitle && capturedTrackLabel) {
subtitle = capturedTrackLabel;
}
$: { $: {
const settings = { const settings = {
selectedPreset, selectedPreset,
@@ -126,6 +133,7 @@
glowIntensity, glowIntensity,
logoSpin, logoSpin,
logoSpinSpeed, logoSpinSpeed,
autoSubtitle,
titlePosition, titlePosition,
}; };
try { try {
@@ -183,6 +191,7 @@
glowIntensity = defaults.glowIntensity; glowIntensity = defaults.glowIntensity;
logoSpin = defaults.logoSpin; logoSpin = defaults.logoSpin;
logoSpinSpeed = defaults.logoSpinSpeed; logoSpinSpeed = defaults.logoSpinSpeed;
autoSubtitle = defaults.autoSubtitle;
titlePosition = defaults.titlePosition; titlePosition = defaults.titlePosition;
} }
@@ -311,6 +320,7 @@
{glowIntensity} {glowIntensity}
{logoSpin} {logoSpin}
{logoSpinSpeed} {logoSpinSpeed}
bind:capturedTrackLabel
bind:isListening bind:isListening
bind:fileCurrentTime bind:fileCurrentTime
bind:fileDuration bind:fileDuration
@@ -381,6 +391,7 @@
bind:glowIntensity bind:glowIntensity
bind:logoSpin bind:logoSpin
bind:logoSpinSpeed bind:logoSpinSpeed
bind:autoSubtitle
bind:titlePosition bind:titlePosition
{isListening} {isListening}
{colorPresets} {colorPresets}

View File

@@ -39,6 +39,9 @@
let currentStream = null; let currentStream = null;
let audioElement = null; let audioElement = null;
let audioSourceNode = null; let audioSourceNode = null;
let capturedAudioTrack = null;
let tabTitleInterval = null;
export let capturedTrackLabel = "";
let dataArray = new Uint8Array(128); let dataArray = new Uint8Array(128);
let bufferLength = 128; let bufferLength = 128;
@@ -274,6 +277,16 @@
// Stop the video track immediately — we only need audio // Stop the video track immediately — we only need audio
stream.getVideoTracks().forEach((t) => t.stop()); stream.getVideoTracks().forEach((t) => t.stop());
// Store audio track for label polling (tab title)
capturedAudioTrack = audioTracks[0];
tabTitleInterval = setInterval(() => {
if (capturedAudioTrack && capturedAudioTrack.readyState === "live") {
capturedTrackLabel = capturedAudioTrack.label || "";
} else {
capturedTrackLabel = "";
}
}, 1000);
// Handle stream ending (user clicks "Stop sharing") // Handle stream ending (user clicks "Stop sharing")
stream.addEventListener("inactive", () => stopListening()); stream.addEventListener("inactive", () => stopListening());
audioTracks.forEach((track) => audioTracks.forEach((track) =>
@@ -721,6 +734,12 @@
audioContext = null; audioContext = null;
} }
audioSourceNode = null; audioSourceNode = null;
capturedAudioTrack = null;
if (tabTitleInterval) {
clearInterval(tabTitleInterval);
tabTitleInterval = null;
}
capturedTrackLabel = "";
isListening = false; isListening = false;
dataArray = new Uint8Array(bufferLength); dataArray = new Uint8Array(bufferLength);
draw(); draw();
@@ -793,6 +812,7 @@
onDestroy(() => { onDestroy(() => {
if (animationId) cancelAnimationFrame(animationId); if (animationId) cancelAnimationFrame(animationId);
if (audioContext) audioContext.close(); if (audioContext) audioContext.close();
if (tabTitleInterval) clearInterval(tabTitleInterval);
window.removeEventListener("resize", updateSize); window.removeEventListener("resize", updateSize);
}); });
</script> </script>
@@ -807,9 +827,9 @@
{#if logoUrl} {#if logoUrl}
<div <div
class="logo-container" class="logo-container"
style="width: {baseRadius * 2}px; height: {baseRadius * 2}px; {logoSpin class:spinning={logoSpin}
? `animation: logo-spin ${Math.max(0.5, 20 / logoSpinSpeed)}s linear infinite` style="width: {baseRadius * 2}px; height: {baseRadius *
: ''}" 2}px; --spin-duration: {Math.max(0.5, 20 / logoSpinSpeed)}s"
> >
<img src={logoUrl} alt="Logo" /> <img src={logoUrl} alt="Logo" />
</div> </div>
@@ -861,7 +881,11 @@
object-fit: cover; object-fit: cover;
} }
@keyframes logo-spin { .logo-container.spinning {
animation: logo-spin var(--spin-duration, 4s) linear infinite;
}
@keyframes -global-logo-spin {
from { from {
transform: rotate(0deg); transform: rotate(0deg);
} }

View File

@@ -57,6 +57,7 @@
export let logoSpin = false; export let logoSpin = false;
export let logoSpinSpeed = 5; export let logoSpinSpeed = 5;
export let titlePosition = "top"; export let titlePosition = "top";
export let autoSubtitle = false;
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
@@ -610,7 +611,13 @@
bind:value={subtitle} bind:value={subtitle}
placeholder="Subtitle..." placeholder="Subtitle..."
style="margin-top: 0.35rem" style="margin-top: 0.35rem"
disabled={autoSubtitle}
/> />
<div class="slider-row" style="margin-top: 0.35rem">
<label>
<input type="checkbox" bind:checked={autoSubtitle} /> Auto (Tab Title)
</label>
</div>
<div class="inline-row" style="margin-top: 0.5rem"> <div class="inline-row" style="margin-top: 0.5rem">
<input <input
type="file" type="file"