Kian
DIAdiscord.js - Imagine an app
•Created by Kian on 6/21/2023 in #djs-voice
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}`);
}
});
});
});
},
6 replies