How to include silence in vc recording

I’m trying to record a vc, I’m using this and the module mediaplex for the opus encoder:
const listenStream = connection.receiver.subscribe(member.id, {
end: {
behavior: EndBehaviorType.Manual,
}
});

const opusDecoder = new OpusEncoder(48000, 2);

listenStream.on("data", (packet) => {
const decoded = opusDecoder.decode(packet);
writeStream.write(decoded);
});
const listenStream = connection.receiver.subscribe(member.id, {
end: {
behavior: EndBehaviorType.Manual,
}
});

const opusDecoder = new OpusEncoder(48000, 2);

listenStream.on("data", (packet) => {
const decoded = opusDecoder.decode(packet);
writeStream.write(decoded);
});
The problem here is it won’t record the silences when a member stops speaking for 5 seconds for exemple, is there a way to add them manually, so the length of the final audio is reflective of the actual time the member was recorded for, and not just the moments where they speak?
3 Replies
d.js toolkit
d.js toolkit3mo ago
- What are your intents? GuildVoiceStates is required to receive voice data! - Show what dependencies you are using -- generateDependencyReport() is exported from @discordjs/voice. - Try looking at common examples: https://github.com/discordjs/voice-examples. - 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! - Marked as resolved by OP
pat
pat3mo ago
you're going to need to add silence frames when the user isn't speaking idk if there's anything in the library to help do this but it will be similar to how audioresource does it (since there's an option to add silence padding frames when playing audio) https://github.com/discordjs/discord.js/blob/main/packages/voice/src/audio/AudioResource.ts#L154-L159 damn i swear there used to be a bot to auto embed this
if (this.silenceRemaining === 0) {
return null;
} else if (this.silenceRemaining > 0) {
this.silenceRemaining--;
return SILENCE_FRAME;
}
...
return this.playStream().read();
if (this.silenceRemaining === 0) {
return null;
} else if (this.silenceRemaining > 0) {
this.silenceRemaining--;
return SILENCE_FRAME;
}
...
return this.playStream().read();
Nitsugua38
Nitsugua38OP3mo ago
yes managed to do it that way thanks
Want results from more Discord servers?
Add your server