Loso
Loso

Reputation: 84

onUserSpeaking() event being called once

I am trying to check if a user starts talking on a channel. I found that i can do this "easily" using ConnectionListener, but for some reason the method is being called only for the first time someone speaks. (which is weird becouse according to the JDA docs, it should be fired 2 times, at the beggining, and at the end of a transmission.

package functionality;

import net.dv8tion.jda.api.audio.hooks.ConnectionListener;
import net.dv8tion.jda.api.audio.hooks.ConnectionStatus;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

public class SpeechRecognition extends ListenerAdapter implements ConnectionListener {

    @Override
    public void onPing(long ping) {
        System.out.println("PING: " + ping);
    }

    @Override
    public void onStatusChange(ConnectionStatus status) {
        System.out.println("STATUS: " + status);
    }

    @Override
    public void onUserSpeaking(User user, boolean speaking) {

    }

    @Override
    public void onUserSpeaking(User user, boolean speaking, boolean soundshare) {
        System.out.println("SPEAKING: " + speaking + " | " + user.getName() + " | " + soundshare);
    }
}

It also works again whenever i for example move the bot to a different channel, and then i speak in it.

Here is my console output:

The bot is now connected to the voice channel.
STATUS: CONNECTING_AWAITING_WEBSOCKET_CONNECT
STATUS: CONNECTING_AWAITING_AUTHENTICATION
STATUS: CONNECTING_ATTEMPTING_UDP_DISCOVERY
STATUS: CONNECTING_AWAITING_READY
PING: 203
STATUS: CONNECTED
SPEAKING: true | Losokos | false   //When i started speaking
PING: 103
PING: 138
PING: 132
PING: 108
PING: 121

Upvotes: 1

Views: 115

Answers (1)

Minn
Minn

Reputation: 6131

This no longer works because Discord has changed how these events work. What you are observing is the new behavior where speaking updates are only sent once.

To detect speaking start/end you must use voice receive. That is also how the Discord client handles speaking indicators, by checking if the user is sending any audio.

Upvotes: 1

Related Questions