Voice Stream for personal radio

Hello, I want to create a radio, I would like it to be managed and animated from discord. how can i get what all the users in the room are saying and send it to my audio stream server? don't hesitate to let me know if you have an idea and if it's possible to do it.
5 Replies
d.js toolkit
d.js toolkit4mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Sykexz
Sykexz4mo ago
yes this is possible
Antonin
AntoninOP4mo ago
with example i have this error :
Antonin
AntoninOP4mo ago
code :
import { createWriteStream } from 'node:fs';
import { pipeline } from 'node:stream';
import { EndBehaviorType, VoiceReceiver } from '@discordjs/voice';
import type { User } from 'discord.js';
import * as prism from 'prism-media';

function getDisplayName(userId: string, user?: User) {
return user ? `${user.username}_${user.discriminator}` : userId;
}

export function createListeningStream(receiver: VoiceReceiver, userId: string, user?: User) {
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 1000,
},
});

const oggStream = new prism.opus.OggLogicalBitstream({
opusHead: new prism.opus.OpusHead({
channelCount: 2,
sampleRate: 48000,
}),
pageSizeControl: {
maxPackets: 10,
},
});

const filename = `./recordings/${Date.now()}-${getDisplayName(userId, user)}.ogg`;

const out = createWriteStream(filename);

console.log(`👂 Started recording ${filename}`);

pipeline(opusStream, oggStream, out, (err?: { message: string }) => {
if (err) {
console.warn(`❌ Error recording file ${filename} - ${err.message}`);
} else {
console.log(`✅ Recorded ${filename}`);
}
});
}
import { createWriteStream } from 'node:fs';
import { pipeline } from 'node:stream';
import { EndBehaviorType, VoiceReceiver } from '@discordjs/voice';
import type { User } from 'discord.js';
import * as prism from 'prism-media';

function getDisplayName(userId: string, user?: User) {
return user ? `${user.username}_${user.discriminator}` : userId;
}

export function createListeningStream(receiver: VoiceReceiver, userId: string, user?: User) {
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 1000,
},
});

const oggStream = new prism.opus.OggLogicalBitstream({
opusHead: new prism.opus.OpusHead({
channelCount: 2,
sampleRate: 48000,
}),
pageSizeControl: {
maxPackets: 10,
},
});

const filename = `./recordings/${Date.now()}-${getDisplayName(userId, user)}.ogg`;

const out = createWriteStream(filename);

console.log(`👂 Started recording ${filename}`);

pipeline(opusStream, oggStream, out, (err?: { message: string }) => {
if (err) {
console.warn(`❌ Error recording file ${filename} - ${err.message}`);
} else {
console.log(`✅ Recorded ${filename}`);
}
});
}
"dependencies": {
"@discordjs/opus": "^0.8.0",
"@discordjs/voice": "^0.11.0",
"discord-api-types": "^0.37.95",
"discord.js": "^13.10.3",
"libsodium-wrappers": "^0.7.10",
"node-crc": "^1.3.2",
"prism-media": "^2.0.0-alpha.0",
"tslib": "^2.6.3"
},
"dependencies": {
"@discordjs/opus": "^0.8.0",
"@discordjs/voice": "^0.11.0",
"discord-api-types": "^0.37.95",
"discord.js": "^13.10.3",
"libsodium-wrappers": "^0.7.10",
"node-crc": "^1.3.2",
"prism-media": "^2.0.0-alpha.0",
"tslib": "^2.6.3"
},
I don't have it in the project's .json package, should I install it? it's good thanks you ! I'm trying to record, but for the moment the bot is launching. all is working thanks you for you help me oh i have just this error :
(node:261732) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [AudioReceiveStream]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit
(node:261732) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [AudioReceiveStream]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit
why this error ?
(node:275940) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [AudioReceiveStream]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit
at genericNodeError (node:internal/errors:983:15)
at wrappedFn (node:internal/errors:537:14)
at _addListener (node:events:594:17)
at AudioReceiveStream.addListener (node:events:612:10)
at Readable.on (node:internal/streams/readable:1126:35)
at AudioReceiveStream.once (node:events:656:8)
at pipe (node:internal/streams/pipeline:440:11)
at pipelineImpl (node:internal/streams/pipeline:373:25)
at pipeline (node:internal/streams/pipeline:185:10)
at createListeningStream (C:\Users\nordi\Desktop\voice-examples-main\recorder\dist\createListeningStream.js:31:32)
(node:275940) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [AudioReceiveStream]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit
at genericNodeError (node:internal/errors:983:15)
at wrappedFn (node:internal/errors:537:14)
at _addListener (node:events:594:17)
at AudioReceiveStream.addListener (node:events:612:10)
at Readable.on (node:internal/streams/readable:1126:35)
at AudioReceiveStream.once (node:events:656:8)
at pipe (node:internal/streams/pipeline:440:11)
at pipelineImpl (node:internal/streams/pipeline:373:25)
at pipeline (node:internal/streams/pipeline:185:10)
at createListeningStream (C:\Users\nordi\Desktop\voice-examples-main\recorder\dist\createListeningStream.js:31:32)
import { createWriteStream } from 'node:fs';
import { pipeline } from 'node:stream';
import { EndBehaviorType, VoiceReceiver } from '@discordjs/voice';
import type { User } from 'discord.js';
import * as prism from 'prism-media';

function getDisplayName(userId: string, user?: User) {
return user ? `${user.username}_${user.discriminator}` : userId;
}

export function createListeningStream(receiver: VoiceReceiver, userId: string, user?: User) {
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 1000,
},
});

const oggStream = new prism.opus.OggLogicalBitstream({
opusHead: new prism.opus.OpusHead({
channelCount: 2,
sampleRate: 48000,
}),
pageSizeControl: {
maxPackets: 10,
},
});

const filename = `./recordings/${Date.now()}-${getDisplayName(userId, user)}.ogg`;

const out = createWriteStream(filename);

console.log(`👂 Started recording ${filename}`);

pipeline(opusStream, oggStream, out, (err) => {
if (err) {
console.warn(`❌ Error recording file ${filename} - ${err.message}`);
} else {
console.log(`✅ Recorded ${filename}`);
}
});
}
import { createWriteStream } from 'node:fs';
import { pipeline } from 'node:stream';
import { EndBehaviorType, VoiceReceiver } from '@discordjs/voice';
import type { User } from 'discord.js';
import * as prism from 'prism-media';

function getDisplayName(userId: string, user?: User) {
return user ? `${user.username}_${user.discriminator}` : userId;
}

export function createListeningStream(receiver: VoiceReceiver, userId: string, user?: User) {
const opusStream = receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 1000,
},
});

const oggStream = new prism.opus.OggLogicalBitstream({
opusHead: new prism.opus.OpusHead({
channelCount: 2,
sampleRate: 48000,
}),
pageSizeControl: {
maxPackets: 10,
},
});

const filename = `./recordings/${Date.now()}-${getDisplayName(userId, user)}.ogg`;

const out = createWriteStream(filename);

console.log(`👂 Started recording ${filename}`);

pipeline(opusStream, oggStream, out, (err) => {
if (err) {
console.warn(`❌ Error recording file ${filename} - ${err.message}`);
} else {
console.log(`✅ Recorded ${filename}`);
}
});
}
pat
pat4mo ago
warning happens when you start speaking but you are already subscribed to the user, pipeline creates error and close listeners to know when the stream ends tbh it's an issue with the implementation in voice-examples Since if this happens you already get the existing stream (so from the first time 'start' is emitted), and that's what you are adding multiple close and error listeners to
Want results from more Discord servers?
Add your server