KaiFireborn
KaiFireborn
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by KaiFireborn on 1/21/2024 in #djs-voice
Saving an opus stream from a voice channel to .mp3/.wav/.webm
So with the help of another thread here, I managed to save an opus stream to .ogg. Now, I need to save that same opus stream to an .mp3 file instead, and i’m even more stuck than last time. Can I somehow save the audio to a .mp3 or .wav file instead? Help would be much mich appreciated…
const { opus } = require("prism-media");

//other stuff

let opusStream = voiceReceiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: allowedPauseDurationForInputVoice
}
});
const oggStream = new opus.OggLogicalBitstream({
opusHead: new opus.OpusHead({
channelCount: 2,
sampleRate: 48000
}),
pageSizeControl: {
maxPackets: 10
}
});

let buffer = [];
oggStream.on("data", (chunk) => {
buffer.push(chunk);
});

opusStream.on("end", async () => {
logReliably(user.globalName + " stopped speaking. " + getTimeElapsedSinceLastCall());
oggStream.destroy()
fs.createWriteStream('output.ogg').write(Buffer.concat(buffer))
buffer = []
});

opusStream.pipe(oggStream)
const { opus } = require("prism-media");

//other stuff

let opusStream = voiceReceiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: allowedPauseDurationForInputVoice
}
});
const oggStream = new opus.OggLogicalBitstream({
opusHead: new opus.OpusHead({
channelCount: 2,
sampleRate: 48000
}),
pageSizeControl: {
maxPackets: 10
}
});

let buffer = [];
oggStream.on("data", (chunk) => {
buffer.push(chunk);
});

opusStream.on("end", async () => {
logReliably(user.globalName + " stopped speaking. " + getTimeElapsedSinceLastCall());
oggStream.destroy()
fs.createWriteStream('output.ogg').write(Buffer.concat(buffer))
buffer = []
});

opusStream.pipe(oggStream)
91 replies
DIAdiscord.js - Imagine an app
Created by KaiFireborn on 1/20/2024 in #djs-voice
How to save a user's voice to a local file? (.mp3 or .ogg)
let listener = voiceReceiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: allowedPauseDurationForInputVoice
}
});

const listenBuffer = [];

listener.on("data", (chunk) => {
listenBuffer.push(chunk);
});

listener.once("end", async () => {
logReliably(user.globalName + " stopped speaking. " + getTimeElapsedSinceLastCall());
const completeBuffer = Buffer.concat(listenBuffer);

const audioEncoder = new OpusEncoder(48000, 2);
//Save to ./test.ogg ?
});
let listener = voiceReceiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: allowedPauseDurationForInputVoice
}
});

const listenBuffer = [];

listener.on("data", (chunk) => {
listenBuffer.push(chunk);
});

listener.once("end", async () => {
logReliably(user.globalName + " stopped speaking. " + getTimeElapsedSinceLastCall());
const completeBuffer = Buffer.concat(listenBuffer);

const audioEncoder = new OpusEncoder(48000, 2);
//Save to ./test.ogg ?
});
completeBuffer definitely holds data, but I tried everything I could find in documentation/forums and still failed to save that buffer's contents as a file. I also tried saving the voiceReceiver stream, and that failed to output a playable audio file as well. Help would be much appreciated!
43 replies