I’m trying to record audio from a voice channel in discord using v13 of discord.js. Here is my code :
const { joinVoiceChannel } = require("@discordjs/voice");
const fs = require("fs");
var { streams } = require("streams.js");
var voiceChannel = interaction.member.voice.channel;
streams[voiceChannel.id] = fs.createWriteStream("test.pcm");
const connection = await joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false
});
const audio = connection.receiver.subscribe(`${interaction.user.id}`, {encoding: "utf-8"});
audio.pipe(streams[voiceChannel.id]);
then the stop command :
…
streams[voiceChannel.id].close();
delete streams[voiceChannel.id];
And when I convert the pcm to wav using ffmpeg -f s16le -ar 44.1k -ac 2 -i test.pcm file.wav, it returns a short audio without my voice but the noise "ffffffffffff"
Why ?
Thank you for your help.