Jiron
Jiron
DIAdiscord.js - Imagine an app
Created by Jiron on 4/1/2024 in #djs-voice
Voice receiver doesn't pick up soundboard sounds
I have a pretty fancy discord bot that uses a voice receiver to pick up audio from users. const audioStream = getVoiceConnection(guildId).receiver.subscribe(userId, { end: { behavior: EndBehaviorType.AfterInactivity, duration: 100 } }); Is the very very very simplified version of it I suppose. That audioStream is then replayed into voice channel so it echoes the user by it's Id. Something like:
const audioPlayer = createAudioPlayer();
connection.subscribe(audioPlayer);
const resource = createAudioResource(audioStream, { inputType: StreamType.Raw });
audioPlayer.play(resource);
const audioPlayer = createAudioPlayer();
connection.subscribe(audioPlayer);
const resource = createAudioResource(audioStream, { inputType: StreamType.Raw });
audioPlayer.play(resource);
Might explain what I'm going for It works perfectly fine but what I noticed is that it does NOT pick up audio from soundboards. Is there maybe a chance that soundboards are handled differently from spoken audio? Is this something that has to be implemented or was it already implemented and I was just too stupid to understand the docs?
5 replies
DIAdiscord.js - Imagine an app
Created by Jiron on 3/7/2023 in #djs-voice
Mix receiver streams efficiently
Anyone know how to mix receiver streams efficiently (in real time by keeping it a stream, no ffmpeg)? I tried using an npm library, audio-mixer, works but sounds horrible. Is there other libraries, maybe something built in...? I heard web audio api is a thing, but dont understand how to combine that with streams and then use the mixed stream in my node.js app. Any other ideas or examples?
217 replies
DIAdiscord.js - Imagine an app
Created by Jiron on 3/5/2023 in #djs-voice
Pipe something into a AudioReceiveStream
I'm trying to pipe a stream into an AudioReceiveStream:
let opusStream = new AudioReceiveStream({
end: EndBehaviorType.Manual
});
let someAudioStream = connection.receiver.subscribe('User ID', { end: { behavior: EndBehaviorType.AfterSilence, duration: 200 } });
someAudioStream.pipe(opusStream);
let opusStream = new AudioReceiveStream({
end: EndBehaviorType.Manual
});
let someAudioStream = connection.receiver.subscribe('User ID', { end: { behavior: EndBehaviorType.AfterSilence, duration: 200 } });
someAudioStream.pipe(opusStream);
However, I get the error:
node:internal/streams/readable:766
const ret = dest.write(chunk);
^

TypeError: dest.write is not a function
at AudioReceiveStream.ondata (node:internal/streams/readable:766:22)
at AudioReceiveStream.emit (node:events:525:35)
at Readable.read (node:internal/streams/readable:539:10)
at flow (node:internal/streams/readable:1023:34)
at resume_ (node:internal/streams/readable:1004:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
node:internal/streams/readable:766
const ret = dest.write(chunk);
^

TypeError: dest.write is not a function
at AudioReceiveStream.ondata (node:internal/streams/readable:766:22)
at AudioReceiveStream.emit (node:events:525:35)
at Readable.read (node:internal/streams/readable:539:10)
at flow (node:internal/streams/readable:1023:34)
at resume_ (node:internal/streams/readable:1004:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
I am very new to streams as you can probably tell by my previous posts. Anyways, do I have to do that differently / how can I pipe something into an AudioReceiveStream?
3 replies
DIAdiscord.js - Imagine an app
Created by Jiron on 3/5/2023 in #djs-voice
How do I create a continuous opus stream?
I want to pipe data into an opusstream and play that opusstream continuously so can then do something like this. Only way I see doing that is through receiver.subscribe(...); but in my case, it's not really practical. Here is a small example of what I want to do: let opusStream = //what do I enter here? mixer.pipe(opusStream); const audioPlayer = createAudioPlayer(); connection.subscribe(audioPlayer); const resource = createAudioResource(opusStream, { inputType: StreamType.Opus }); audioPlayer.play(resource); I get the data through a speaking event which then fires the following code: function playStream(receiver, userId) { const audioStream = receiver.subscribe(userId, { end: { behavior: EndBehaviorType.AfterSilence, duration: 200 } }); const input = mixer.input({ volume: 75 });
audioStream .on("data", (chunk) => { const buffer = encoder.decode(chunk); input.write(buffer); }) .on("error", (err) => { console.log(err) }) .on("end", () => { mixer.removeInput(input); }); } And "mixer" is then the stream which I want to output, since it mixes all user receiver together into one stream.
5 replies
DIAdiscord.js - Imagine an app
Created by Jiron on 3/5/2023 in #djs-voice
Bot stops listening after 1 minute
I am currently working on a Discord bot which has the purpose of listening to what other people say. I got it to repeat whatever users say into their microphones through a receiver. Since there is no speaking event anymore, that made things more difficult but thats not what I want to ask. I realized that when the bot stops receiving inputs from the users and thus does not play audio anymore, after one minute it fires a "voiceStateUpdate" event on the bot. Logging both oldMember and newMember does not give me any more information, since they are both identical logs: client.on('voiceStateUpdate', (oldMember, newMember) => { console.log(oldMember, newMember); // oldMember is the same as newMember when this happens }); The thing that changes though, is that the bot does not listen to anything anymore. logging: "connection.receiver.speaking.users" shows me, that it cannot display the users that are actually talking anymore, because the bot is most probably not listening to them anymore. I read an old bugreport where it would stop listening after 5 minutes. that was djs v12 though. They fixed it by playing a silent noise. Im not really sure how to do that, but I really dont want to be playing a silent sound every minute just because of that. What can be the reason of that? Is there some kind of setting that I have to add to "joinVoiceChannel"? RIght now it just looks like this: client.on("messageCreate", (message) => { if(message.author.id != "501819491764666386") return; const voicechannel = message.member.voice.channel; if(!voicechannel) return message.channel.send("Please join a vc"); joinVoiceChannel({ channelId: voicechannel.id, guildId: message.guild.id, adapterCreator: message.guild.voiceAdapterCreator, selfDeaf: false }); let connection = getVoiceConnection(message.guild.id); (...) Added the bot only for testing purposes so thats why I dont specifically check for some kind of prefix but rather just if I sent the message.
9 replies
DIAdiscord.js - Imagine an app
Created by Jiron on 11/23/2022 in #djs-voice
Replaying spoken audio
I tried creating a bot that reacts to any message I send and then it should join a voice channel and repeat whatever I say. It does pick up that I speak stuff, no errors in the console, all I realized is that it switches from buffering to playing and then from playing to autopaused immediately. I guess it has something to do with the stream not continuously refreshed and read but I'm very new to streams, especially audio streams and I'm not sure on what to do. I made a reddit post according to this as well but never got a response. I have pastebin over here: https://pastebin.com/gft1WkVn I have imported everything that's needed, everything is pretty much up to date and all intents have been given as well (guilds, guild msgs and guild voicestate) Anyone able to help? Logs look like this btw (excluding ready log): While I'm speaking: Audio player transitioned from buffering to playing Audio player transitioned from playing to autopaused After I'm done speaking: Audio player transitioned from buffering to playing Audio player transitioned from buffering to idle Audio player transitioned from playing to autopaused
19 replies