yahay
yahay
DIAdiscord.js - Imagine an app
Created by yahay on 8/13/2023 in #djs-voice
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
3 replies