Interface AudioSendHandler


public interface AudioSendHandler
Interface used to send audio to Discord through JDA.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final AudioFormat
    Audio Input Format expected by JDA if isOpus() returns false.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    If this method returns true JDA will attempt to retrieve audio data from this handler by calling provide20MsAudio().
    default boolean
    If this method returns true JDA will treat the audio data provided by provide20MsAudio() as a pre-encoded 20 Millisecond packet of Opus audio.
    If canProvide() returns true JDA will call this method in an attempt to retrieve audio data from the handler.
  • Field Details

    • INPUT_FORMAT

      static final AudioFormat INPUT_FORMAT
      Audio Input Format expected by JDA if isOpus() 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 calling provide20MsAudio(). 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

      @Nullable ByteBuffer provide20MsAudio()
      If canProvide() 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-backed ByteBuffer. Use either ByteBuffer.allocate(int) or ByteBuffer.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.
      If isOpus() 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 by provide20MsAudio() 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.