prism-media
prism-media copied to clipboard
Decoding in real-time becomes gaped
My question may look a little unrelated to the usage of this particular library.
Basically, I receive an Opus stream from the internet, decode it with prism.opus.Decoder, get PCM packets and stream them forward to the speakers:
events.onAudioData(async ({ event, opusInfo, getStream }) => {
// A stream with Opus packets
const stream = getStream(undefined, false);
const frameSize = (opusInfo.inputSampleRate * opusInfo.frameSize) / 1000;
const opusOpt = {
rate: opusInfo.inputSampleRate,
channels: opusInfo.channels,
frameSize,
};
const opusDecoder = new prism.opus.Decoder(opusOpt);
const normalizer = new NormalizeRateStream({
bufferLengthMs: 2 * 1000,
packetLengthMs: event.packet_duration,
});
const speaker = new Speaker({
channels: opusInfo.channels,
bitDepth: 16,
sampleRate: opusInfo.inputSampleRate,
});
stream.pipe(getOpusStatsStream(pinoLogger)).pipe(opusDecoder).pipe(normalizer).pipe(speaker);
});
There is also a duplex normalizing stream which ensures requested rate of packets per time.
The problem is that sound becomes gaped and I cannot find a way to glue pieces in one steady stream.
I recorded a helping video which demonstrates the problem:
https://www.youtube.com/watch?v=O7Fv3GTMjKQ
Do you have any idea why it's happening?
Hi @OnkelTem, I'm afraid I'm not too sure what is happening either :(
Is onAudioData
only fired once after connecting to the radio? The only thing I can think of is that it is being called repeatedly and giving the weird gap.
The issue is unrelated to the library, however I think I'll keep it open until I run out of ideas :sweat_smile: