Package net.dv8tion.jda.api.audio
Interface AudioSendHandler
public interface AudioSendHandler
Interface used to send audio to Discord through JDA.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final AudioFormat
Audio Input Format expected by JDA ifisOpus()
returns false. -
Method Summary
Modifier and TypeMethodDescriptionboolean
If this method returns true JDA will attempt to retrieve audio data from this handler by callingprovide20MsAudio()
.default boolean
isOpus()
If this method returns true JDA will treat the audio data provided byprovide20MsAudio()
as a pre-encoded 20 Millisecond packet of Opus audio.IfcanProvide()
returns true JDA will call this method in an attempt to retrieve audio data from the handler.
-
Field Details
-
INPUT_FORMAT
Audio Input Format expected by JDA ifisOpus()
returns false. 48KHz 16bit stereo signed BigEndian PCM.
-
-
Method Details
-
canProvide
boolean canProvide()If this method returns true JDA will attempt to retrieve audio data from this handler by callingprovide20MsAudio()
. The return value is checked each time JDA attempts send audio, so if the developer wanted to start and stop sending audio it could be done by changing the value returned by this method at runtime.- Returns:
- If true, JDA will attempt to retrieve audio data from
provide20MsAudio()
-
provide20MsAudio
IfcanProvide()
returns true JDA will call this method in an attempt to retrieve audio data from the handler. This method need to provide 20 Milliseconds of audio data as a array-backedByteBuffer
. Use eitherByteBuffer.allocate(int)
orByteBuffer.wrap(byte[])
.Considering this system needs to be low-latency / high-speed, it is recommended that the loading of audio data be done before hand or in parallel and not loaded from disk when this method is called by JDA. Attempting to load all audio data from disk when this method is called will most likely cause issues due to IO blocking this thread.
The provided audio data needs to be in the format: 48KHz 16bit stereo signed BigEndian PCM.
Defined by:AudioSendHandler.INPUT_FORMAT
.
IfisOpus()
is set to return true, then it should be in pre-encoded Opus format instead.- Returns:
- Should return a
ByteBuffer
containing 20 Milliseconds of audio. - See Also:
-
isOpus
default boolean isOpus()If this method returns true JDA will treat the audio data provided byprovide20MsAudio()
as a pre-encoded 20 Millisecond packet of Opus audio. This means that JDA WILL NOT attempt to encode the audio as Opus, but will provide it to Discord exactly as it is given.- Returns:
- If true, JDA will not attempt to encode the provided audio data as Opus.
Default - False.
-