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
(Funny, couldn't get it to work that way)
91 replies
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
async function onStartedSpeaking(userId, voiceChannel) {
let user = await getUserById(userId);

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 () => {
oggStream.destroy()
let ws = fs.createWriteStream('output.ogg')
ws.write(Buffer.concat(buffer))
logReliably("Finished writing output.ogg")
ws.end()
buffer = []

exec("ffmpeg -y -i output.ogg -ar 48000 -ac 2 -codec:a libmp3lame output.mp3")
});

opusStream.pipe(oggStream)
}
async function onStartedSpeaking(userId, voiceChannel) {
let user = await getUserById(userId);

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 () => {
oggStream.destroy()
let ws = fs.createWriteStream('output.ogg')
ws.write(Buffer.concat(buffer))
logReliably("Finished writing output.ogg")
ws.end()
buffer = []

exec("ffmpeg -y -i output.ogg -ar 48000 -ac 2 -codec:a libmp3lame output.mp3")
});

opusStream.pipe(oggStream)
}
Once again, thanks a ton for your help - it's probably what you meant earlier, too. Definitely couldn't have done it alone..
91 replies
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 in the end, I just decided to run the ffmeg command through the terminal instead of using that prism-media class to convert the written .ogg file to .mp3.
91 replies
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
I couldn't just let the problem hang and focus on my other work
91 replies
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
Okay so being me
91 replies
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
I'll see what I can do in way of debugging tomorrow, but
91 replies
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
Okay I tried real quick, and the problem with end triggering over and over is there again.
91 replies
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
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, saving. " + getTimeElapsedSinceLastCall());
setMuteSelectively(false, true, true, voiceChannel, user.id);

oggStream.destroy()
let ws = fs.createWriteStream('output.ogg')
ws.write(Buffer.concat(buffer))
logReliably("Finished writing output.ogg")
ws.end()
buffer = []

let audioOutput = new prism.FFmpeg({
args: ["-ar", "48000", "-ac", "2", "-codec:a", "libmp3lame", "-i", "ogg_output.ogg", "mp3_output.mp3"]
});

// await transcribe_and_reply(audioOutputFilename);
setMuteSelectively(true, false, false, voiceChannel, user.id);
});

opusStream.pipe(oggStream)
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, saving. " + getTimeElapsedSinceLastCall());
setMuteSelectively(false, true, true, voiceChannel, user.id);

oggStream.destroy()
let ws = fs.createWriteStream('output.ogg')
ws.write(Buffer.concat(buffer))
logReliably("Finished writing output.ogg")
ws.end()
buffer = []

let audioOutput = new prism.FFmpeg({
args: ["-ar", "48000", "-ac", "2", "-codec:a", "libmp3lame", "-i", "ogg_output.ogg", "mp3_output.mp3"]
});

// await transcribe_and_reply(audioOutputFilename);
setMuteSelectively(true, false, false, voiceChannel, user.id);
});

opusStream.pipe(oggStream)
91 replies
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
Yeah I have no idea anymore.. Guess I'll try to continue tomorrow, but I'm pretty sure I'm doing that part wrong
91 replies
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
Wouldn't it break the FFmpeg class?
91 replies
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
But for that I would need the prism-media alpha version again
91 replies
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
It has some kind of opus encoder/decoder, but I couldn't find any documentation
91 replies
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
Maybe we have to use some other library after all. I didn't come far with it previously, but maybe discordjs/opus?
91 replies
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
Yeah it works properly
91 replies
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
Input #0, ogg, from 'output.ogg': Duration: 00:00:02.56, start: 0.000000, bitrate: 59 kb/s Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
91 replies
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
Nothing in that respect should've changed, so
91 replies
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
Well I still have an ogg file saved from yesterday
91 replies
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
I'm not sure if I'm saving it correctly though; When we saved it as .ogg, it used to work
91 replies
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
Invalid data...
91 replies
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
ffprobe version 6.1.1 Copyright (c) 2007-2023 the FFmpeg developers
built with Apple clang version 15.0.0 (clang-1500.1.0.2.5)
configuration: --prefix=/usr/local/Cellar/ffmpeg/6.1.1_2 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopenvino --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox
libavutil 58. 29.100 / 58. 29.100
libavcodec 60. 31.102 / 60. 31.102
libavformat 60. 16.100 / 60. 16.100
libavdevice 60. 3.100 / 60. 3.100
libavfilter 9. 12.100 / 9. 12.100
libswscale 7. 5.100 / 7. 5.100
libswresample 4. 12.100 / 4. 12.100
libpostproc 57. 3.100 / 57. 3.100
output.opus: Invalid data found when processing input
ffprobe version 6.1.1 Copyright (c) 2007-2023 the FFmpeg developers
built with Apple clang version 15.0.0 (clang-1500.1.0.2.5)
configuration: --prefix=/usr/local/Cellar/ffmpeg/6.1.1_2 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopenvino --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox
libavutil 58. 29.100 / 58. 29.100
libavcodec 60. 31.102 / 60. 31.102
libavformat 60. 16.100 / 60. 16.100
libavdevice 60. 3.100 / 60. 3.100
libavfilter 9. 12.100 / 9. 12.100
libswscale 7. 5.100 / 7. 5.100
libswresample 4. 12.100 / 4. 12.100
libpostproc 57. 3.100 / 57. 3.100
output.opus: Invalid data found when processing input
91 replies