#How to format data when using StreamType.Raw or StreamType.Opus

7 messages · Page 1 of 1 (latest)

glossy atlas
#

I have a program that can send either Opus data or PCM data (I can choose one of the two), and I have a discord bot that can receive that data. The only way I've gotten it to play properly in a voice channel is by using StreamType.Arbitrary and manually adding a WAV header to the resource. If I try to use StreamType.Raw to play PCM data, the audio comes out twice as fast, and if I use Opus, it comes out so fast I can barely even hear the music. I assume it must be because discord.js/voice is treating the stereo audio as if it was mono, but I have no idea and I have even less of an idea of what to do to fix this aside from just using StreamType.Arbitrary.

spiral caveBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

glossy atlas
glossy atlas
#

Update: managed to figure out - in order to use either StreamType.Raw or StreamType.Opus, frameSize must be 960 otherwise things get ugly

#

now i can play PCM data fine but Opus is still a bit weird

#
const stream = ...; // a stream containing opus data
const resource = createAudioResource(stream, {
    inputType: StreamType.Opus
});

this works fine excuse me this is the example that doesn't play any audio at all

#
const stream = ...; // a stream containing opus data
const wtf = new opus.Decoder({
    rate: 48_000,
    channels: 2,
    frameSize: 960
});

const wtf2 = new opus.Encoder({
    rate: 48_000,
    channels: 2,
    frameSize: 960
});

stream.pipe(wtf);
wtf.pipe(wtf2);

const resource = createAudioResource(wtf2, {
    inputType: StreamType.Opus
});

but THIS one works fine and i have no idea why