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.
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const { joinVoiceChannel, EndBehaviorType } = require('@discordjs/voice');
const fs = require('fs');
const { opus } = require('prism-media');
const wav = require('node-wav');
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,
selfDeaf: false
});
connection.receiver.speaking.on('start', (userId) => {
const audio = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 100,
},
});
const opusDecoder = new opus.Decoder({ channels: 1, rate: 48000, frameSize: 960 });
const pcmData = [];
opusDecoder.on('data', (chunk) => {
pcmData.push(chunk);
});
opusDecoder.on('end', () => {
const wavFileName = `./rec/${Date.now()}-${userId}.wav`;
const wavData = wav.encode(pcmData, {
sampleRate: 48000,
float: false,
bitDepth: 16,
channels: 1,
});
fs.writeFileSync(wavFileName, wavData);
console.log(`✅ Recorded ${wavFileName}`);
});
audio.pipe(opusDecoder);
});
}
});
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const { joinVoiceChannel, EndBehaviorType } = require('@discordjs/voice');
const fs = require('fs');
const { opus } = require('prism-media');
const wav = require('node-wav');
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,
selfDeaf: false
});
connection.receiver.speaking.on('start', (userId) => {
const audio = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 100,
},
});
const opusDecoder = new opus.Decoder({ channels: 1, rate: 48000, frameSize: 960 });
const pcmData = [];
opusDecoder.on('data', (chunk) => {
pcmData.push(chunk);
});
opusDecoder.on('end', () => {
const wavFileName = `./rec/${Date.now()}-${userId}.wav`;
const wavData = wav.encode(pcmData, {
sampleRate: 48000,
float: false,
bitDepth: 16,
channels: 1,
});
fs.writeFileSync(wavFileName, wavData);
console.log(`✅ Recorded ${wavFileName}`);
});
audio.pipe(opusDecoder);
});
}
});
8 replies
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.
8 replies
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.
Converted to mp3
8 replies
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 did this, but still only noise is recorded.
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,
selfDeaf:false
});
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,
selfDeaf:false
});
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}`);
}
});
});
}
});
8 replies
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.
8 replies
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.
Version:
NodeJS:v19.2.0
OS:Windows11
{
"dependencies": {
"@discordjs/voice": "^0.16.0",
"@google-cloud/speech": "^5.6.0",
"discord.js": "^14.11.0",
"ffmpeg-static": "^5.1.0",
"libsodium-wrappers": "^0.7.11",
"node-opus": "^0.3.3",
"prism-media": "^1.3.5",
"wav-encoder": "^1.3.0"
}
}
{
"dependencies": {
"@discordjs/voice": "^0.16.0",
"@google-cloud/speech": "^5.6.0",
"discord.js": "^14.11.0",
"ffmpeg-static": "^5.1.0",
"libsodium-wrappers": "^0.7.11",
"node-opus": "^0.3.3",
"prism-media": "^1.3.5",
"wav-encoder": "^1.3.0"
}
}
8 replies