Have speaking's data

connection.receiver.speaking.on('start', async (userId) => {
const receiverOptions = {
mode: 'mp3',
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 500
}
};

connection.receiver.subscribe(userId, receiverOptions);

})
connection.receiver.speaking.on("end", async (data, data2) => {
console.log(data)
})
connection.receiver.speaking.on('start', async (userId) => {
const receiverOptions = {
mode: 'mp3',
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 500
}
};

connection.receiver.subscribe(userId, receiverOptions);

})
connection.receiver.speaking.on("end", async (data, data2) => {
console.log(data)
})
please how to have the data collected ?
9 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
dx0_
dx0_OP2y ago
I tried with an convert but its useless
duck
duck2y ago
connection.receiver.subscribe() returns the receive stream (a stream of opus packets) you're currently not storing it or doing anything with it the end SpeakingMap event doesn't emit with the data, it emits with the id of the user who stopped speaking you can make use of prism-media (a dependency of @discorjs/voice) and use its opus.Decoder class to decode the opus packet stream to raw pcm you can then use ffmpeg to convert to mp3 there is no mode option for <VoiceReceiver>.subscribe()
d.js docs
d.js docs2y ago
method VoiceReceiver#subscribe() Creates a subscription for the given user method (static) SpeakingMap.on() ```js (more...)
dx0_
dx0_OP2y ago
thanks br o i will see tomorow I have this :
connection.receiver.speaking.on('start', async (userId) => {
const receiverOptions = {
mode: 'mp3',
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 500
}
};

const t = connection.receiver.subscribe(userId, receiverOptions);
const decoder = new prism.opus.Decoder({
channels: 2,
rate: 48000,
frameSize: 960,
});

const outputFileStream = fs.createWriteStream('audio_output.mp3');
t.pipe(decoder).pipe(outputFileStream);


})
connection.receiver.speaking.on("end", async (data) => {
console.log(data)
})
connection.receiver.speaking.on('start', async (userId) => {
const receiverOptions = {
mode: 'mp3',
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 500
}
};

const t = connection.receiver.subscribe(userId, receiverOptions);
const decoder = new prism.opus.Decoder({
channels: 2,
rate: 48000,
frameSize: 960,
});

const outputFileStream = fs.createWriteStream('audio_output.mp3');
t.pipe(decoder).pipe(outputFileStream);


})
connection.receiver.speaking.on("end", async (data) => {
console.log(data)
})
but I dont no how to convert in mp3 with fmmpeg
duck
duck2y ago
you can use this as for what args to use, that'd be a question for google
dx0_
dx0_OP2y ago
const inputFile = connection.receiver.subscribe(userId, receiverOptions);
const outputFile = fs.createWriteStream('./audio mp3.mp3');

const transcoder = new prism.FFmpeg({
args: [
'-i', 'pipe:0',
'-f', 'mp3',
'-q:a', '0',
'pipe:1'
]
});

inputFile.pipe(transcoder)
.pipe(outputFile)
.on('finish', () => {
console.log('Conversion terminée !');
})
.on('error', (err) => {
console.error('Une erreur s\'est produite lors de la conversion :', err);
});
const inputFile = connection.receiver.subscribe(userId, receiverOptions);
const outputFile = fs.createWriteStream('./audio mp3.mp3');

const transcoder = new prism.FFmpeg({
args: [
'-i', 'pipe:0',
'-f', 'mp3',
'-q:a', '0',
'pipe:1'
]
});

inputFile.pipe(transcoder)
.pipe(outputFile)
.on('finish', () => {
console.log('Conversion terminée !');
})
.on('error', (err) => {
console.error('Une erreur s\'est produite lors de la conversion :', err);
});
I did this but in the mp3 file, there is nothing
duck
duck2y ago
not sure why you've removed the Decoder @dx0_
Want results from more Discord servers?
Add your server