fix: add extra margin to avoid audios cutting off early

This commit is contained in:
2026-01-15 13:14:30 -03:00
parent 00e02b9f97
commit b3109d643d
+5 -2
View File
@@ -11,6 +11,8 @@ import { PassThrough, Readable } from 'stream';
import prism from 'prism-media';
const DURATION_MARGIN_PCT = 0.25;
export class StreamQueue {
private queue: Readable[] = [];
private isPlaying = false;
@@ -133,13 +135,13 @@ export class MixedStream {
});
transcoder.on('end', () => {
const durationMs = (totalBytes / 192000) * 1000;
const durationMs = (totalBytes / 192000) * 1000 * (1 + DURATION_MARGIN_PCT);
setTimeout(() => {
source.unpipe(transcoder);
transcoder.unpipe(mixerInput);
this.mixer.removeAudioinput(mixerInput);
transcoder.destroy();
this.mixer.removeAudioinput(mixerInput);
resolve();
}, durationMs);
});
@@ -151,6 +153,7 @@ export class MixedStream {
});
source.pipe(transcoder).pipe(mixerInput);
});
}