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
Pastebin
client.on("messageCreate", (message) => { if(message.author.id != ...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
13 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Jiron
JironOP2y ago
Discord version is the newest v14, I'm currently not on my pc but can update it once I am.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Jiron
JironOP2y ago
Great input, so I would guess I should set it to play? I will try this this noon Also, if that wouldnt work, would you say it's rather the player's or the receiver's fault?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Jiron
JironOP2y ago
Sadly didn't work.. Logs looked like this: the bot is online! conn Audio player transitioned from buffering to playing Audio player transitioned from playing to idle Audio player transitioned from buffering to idle It always logs the three "Audio player transitioned..." logs at once when talking, nothing gets logged when you stop To be honest I'm sad about the update, it was possible to do that with discord js v12 just like this: const audio = connectionA.receiver.createStream('User ID'); connectionB.play(audio, { type: 'opus' }); though connectionB could also be connectionA if you want to hear yourself Sadly don't have any updates on this and still am kind of stuck. I guess Imma have to figure out how to connect a discordjsv12 code part with a discordjsv14 code part
pat
pat2y ago
const {
createAudioPlayer,
createAudioResource,
EndBehaviorType,
StreamType,
} = require('@discordjs/voice');

const opusStream = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 500,
},
});
const audioPlayer = createAudioPlayer();
connection.subscribe(audioPlayer);
const resource = createAudioResource(opusStream, { inputType: StreamType.Opus });
audioPlayer.play(resource);
const {
createAudioPlayer,
createAudioResource,
EndBehaviorType,
StreamType,
} = require('@discordjs/voice');

const opusStream = connection.receiver.subscribe(userId, {
end: {
behavior: EndBehaviorType.AfterSilence,
duration: 500,
},
});
const audioPlayer = createAudioPlayer();
connection.subscribe(audioPlayer);
const resource = createAudioResource(opusStream, { inputType: StreamType.Opus });
audioPlayer.play(resource);
do not recommend wrapping this in a receiver.speaking.on('start') event unless handled correctly
Jiron
JironOP2y ago
Oh, haven't really thought of that. Im gonna try this some time but I guess what you said makes sense.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
dzlandis
dzlandis2y ago
The subscribed user is unsubscribed automatically based on the end behavior to my knowledge So in what you replied to, the stream (subscription) is ended on EndBehaviorType.AfterSilence
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
dzlandis
dzlandis2y ago
Ah, good question, not quite sure about that. I've known for a while that manual end behavior is quite finicky so I just use the automatic one.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server