gosso8567
gosso8567
DIAdiscord.js - Imagine an app
Created by gosso8567 on 7/23/2023 in #djs-voice
I want to record audio from Discord's audio channel in Node.js.
I just want to get voice data for now. Current code
const { Client, GatewayIntentBits, Partials, } = require('discord.js');
const { joinVoiceChannel, EndBehaviorType } = require('@discordjs/voice');
const fs = require('node:fs');
const stream = require('node:stream');
const client = new Client({
intents: Object.values(GatewayIntentBits),
partials: [Partials.Message, Partials.Channel, Partials.Reaction], rest: 60000
});
const prefix = '!';
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('messageCreate', async (message) => {
if (message.content.startsWith(prefix + 'join')) {
const voiceChannel = message.member?.voice.channel;
if (!voiceChannel) {
return message.reply('このコマンドを使用するには、音声チャンネルに参加している必要があります。');
}

const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
});
connection.receiver.speaking.on('start', (userId) => {
const audio = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 100,
},
});
var filename = './rec/'.concat(Date.now(), '-').concat(userId, '.pcm');
var out = fs.createWriteStream(filename);
stream.pipeline(audio, out, function (err) {
if (err) {
console.warn(`❌ Error recording file ${filename} - ${err.message}`);
} else {
console.log(`✅ Recorded ${filename}`);
}
});
});
}
});
const { Client, GatewayIntentBits, Partials, } = require('discord.js');
const { joinVoiceChannel, EndBehaviorType } = require('@discordjs/voice');
const fs = require('node:fs');
const stream = require('node:stream');
const client = new Client({
intents: Object.values(GatewayIntentBits),
partials: [Partials.Message, Partials.Channel, Partials.Reaction], rest: 60000
});
const prefix = '!';
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('messageCreate', async (message) => {
if (message.content.startsWith(prefix + 'join')) {
const voiceChannel = message.member?.voice.channel;
if (!voiceChannel) {
return message.reply('このコマンドを使用するには、音声チャンネルに参加している必要があります。');
}

const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
});
connection.receiver.speaking.on('start', (userId) => {
const audio = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 100,
},
});
var filename = './rec/'.concat(Date.now(), '-').concat(userId, '.pcm');
var out = fs.createWriteStream(filename);
stream.pipeline(audio, out, function (err) {
if (err) {
console.warn(`❌ Error recording file ${filename} - ${err.message}`);
} else {
console.log(`✅ Recorded ${filename}`);
}
});
});
}
});
Problem: File is saved, but when played back in Adobe's Audition, it is silent (only +0-2 seconds) Supplementation: No specific errors
8 replies