Ai_Assistant/client/subtitles.js

30 lines
911 B
JavaScript
Raw Permalink Normal View History

2026-05-24 13:31:30 +02:00
// subtitles.js
export function showSubtitleStreaming(text, totalDurationSeconds, mode = "word") {
const container = document.getElementById('subtitle-container');
container.innerHTML = ''; // Clear existing content
container.classList.add('visible');
let segments = mode === "letter" ? [...text] : text.split(' ');
let totalSteps = segments.length;
let delay = (totalDurationSeconds * 1000 *0.7) / totalSteps;
segments.forEach((segment, i) => {
const span = document.createElement('span');
span.style.opacity = '0';
span.style.transition = 'opacity 0.3s ease';
span.textContent = mode === "word" ? segment + ' ' : segment;
container.appendChild(span);
setTimeout(() => {
span.style.opacity = '1';
}, i * delay);
});
// Hide after total duration
setTimeout(() => {
container.classList.remove('visible');
}, totalDurationSeconds * 1000 + 900);
}