Ogg files with no sound

Hi, I followed the github recorder example and managed to record some ogg files using my bot. But the files have no sound and seem to be corrupted. Here is my code for this part.
async execute(interaction) {
await interaction.deferReply();
let connection;
const channel = interaction.member.voice.channel;
if (
interaction.member instanceof GuildMember &&
interaction.member.voice.channel
) {
connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
selfDeaf: false,
selfMute: false,
adapterCreator: channel.guild.voiceAdapterCreator,
});
} else {
await interaction.followUp(
"Join a voice channel"
);
}
await interaction.followUp("Recording");
connection.on("ready", () => {
connection.receiver.speaking.on("start", (user) => {
const opusStream = connection.receiver.subscribe(user, {
end: {
behavior: EndBehaviorType.AfterSilence,
},
});
const oggStream = new opus.OggLogicalBitstream({
opusHead: new opus.OpusHead({
channelCount: 2,
sampleRate: 48000,
}),
pageSizeControl: {
maxPackets: 10,
},
crc: false,
});
const filename = `./recordings/${Date.now()}.ogg`;
const out = createWriteStream(filename);
pipeline(opusStream, oggStream, out, (err) => {
if (err) {
console.warn(
`❌ Error recording file ${filename}`
);
} else {
console.log(`✅ Recorded ${filename}`);
}
});
});
});
},
async execute(interaction) {
await interaction.deferReply();
let connection;
const channel = interaction.member.voice.channel;
if (
interaction.member instanceof GuildMember &&
interaction.member.voice.channel
) {
connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
selfDeaf: false,
selfMute: false,
adapterCreator: channel.guild.voiceAdapterCreator,
});
} else {
await interaction.followUp(
"Join a voice channel"
);
}
await interaction.followUp("Recording");
connection.on("ready", () => {
connection.receiver.speaking.on("start", (user) => {
const opusStream = connection.receiver.subscribe(user, {
end: {
behavior: EndBehaviorType.AfterSilence,
},
});
const oggStream = new opus.OggLogicalBitstream({
opusHead: new opus.OpusHead({
channelCount: 2,
sampleRate: 48000,
}),
pageSizeControl: {
maxPackets: 10,
},
crc: false,
});
const filename = `./recordings/${Date.now()}.ogg`;
const out = createWriteStream(filename);
pipeline(opusStream, oggStream, out, (err) => {
if (err) {
console.warn(
`❌ Error recording file ${filename}`
);
} else {
console.log(`✅ Recorded ${filename}`);
}
});
});
});
},
4 Replies
d.js toolkit
d.js toolkit2y ago
• 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.
Kian
KianOP2y ago
node version: v18.16.0 "@discordjs/opus": "0.8.0", "@discordjs/voice": "0.11.0", "discord.js": "^14.11.0", "dotenv": "^16.3.1", "ffmpeg": "^0.0.4", "fluent-ffmpeg": "^2.1.2", "libsodium-wrappers": "^0.7.11", "prism-media": "2.0.0-alpha.0"
Kian
KianOP2y ago
GitHub
voice-examples/recorder at main · discordjs/voice-examples
A collection of examples of how to use @discordjs/voice in your projects - voice-examples/recorder at main · discordjs/voice-examples
Kian
KianOP2y ago
In the example I sent, the output stream is never flushed/closed. How should I flush/close the stream? Also the output ogg files have the size of 200-300 bytes, so it seems to me that the implementation is not working at all. yeah I thought that wasn't needed. it now works. thanks a lot
Want results from more Discord servers?
Add your server