record and play audio

I am trying to do https://github.com/discordjs/voice-examples/blob/main/recorder/src/createListeningStream.ts in v14 with this code:
function createListeningStream(receiver, userId, user) {
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 5000,
},
});
const decode = new prism.opus.Decoder({
channels: 2,
rate: 48000,
frameSize: 960,
});
const filename = `./recordings/${Date.now()}-${getDisplayName(userId, user)}.ogg`;
const out = createWriteStream(filename);
console.log(`๐Ÿ‘‚ Started recording ${filename}`);

pipeline(opusStream, decode, out, (err) => {
if (err) {
console.warn(`โŒ Error recording file ${filename} - ${err.message}`);
throw err;
} else {
console.log(`โœ… Recorded ${filename}`);
}
});
}
function createListeningStream(receiver, userId, user) {
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 5000,
},
});
const decode = new prism.opus.Decoder({
channels: 2,
rate: 48000,
frameSize: 960,
});
const filename = `./recordings/${Date.now()}-${getDisplayName(userId, user)}.ogg`;
const out = createWriteStream(filename);
console.log(`๐Ÿ‘‚ Started recording ${filename}`);

pipeline(opusStream, decode, out, (err) => {
if (err) {
console.warn(`โŒ Error recording file ${filename} - ${err.message}`);
throw err;
} else {
console.log(`โœ… Recorded ${filename}`);
}
});
}
I either cannot record correctly or I cannot play back correctly. I think I need the params to play back the file, or how to convert to a usable file. basicly do you know where I can get those for this setup because neither primsmedia docs nor the djs docs explain stuff what try to play the file that doesnt work: cat <file> | ffmpeg -f s16le -ar 48000 -ac 2 -i pipe:0 -acodec pcm_s16le -ar 48000 -ac 2 -f wav - | ffplay - sample recording attached
GitHub
voice-examples/recorder/src/createListeningStream.ts at main ยท disc...
A collection of examples of how to use @discordjs/voice in your projects - discordjs/voice-examples
2 Replies
d.js toolkit
d.js toolkitโ€ข16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
yahay
yahayOPโ€ข16mo ago
other details [email protected] node v16.16.0 -------------------------------------------------- Core Dependencies - @discordjs/voice: 0.16.0 - prism-media: 1.3.5 Opus Libraries - @discordjs/opus: 0.9.0 - opusscript: not found Encryption Libraries - sodium-native: not found - sodium: 3.0.2 - libsodium-wrappers: not found - tweetnacl: not found FFmpeg - version: 4.2.3 - libopus: yes --------------------------------------------------
Want results from more Discord servers?
Add your server