DiscordOpusEncoder

open class DiscordOpusEncoder : DiscordOpusCodeable

An Opus encoder.

Takes raw PCM 16-bit-lesample data and returns Opus encoded voice packets.

  • The bitrate for this encoder.

    Declaration

    Swift

    public let bitrate: Int
  • The number of channels.

    Declaration

    Swift

    public let channels: Int
  • The maximum size of a opus packet.

    Declaration

    Swift

    public var maxPacketSize: Int
  • The sampling rate.

    Declaration

    Swift

    public let sampleRate: Int
  • Creates an Encoder that can take raw PCM data and create Opus packets.

    Declaration

    Swift

    public init(bitrate: Int, sampleRate: Int = 48_000, channels: Int = 2, vbr: Bool = false) throws

    Parameters

    bitrate

    The target bitrate for this encoder.

    sampleRate

    The sample rate for the encoder. Discord expects this to be 48k.

    channels

    The number of channels in the stream to encode, should always be 2.

  • Encodes a single frame of raw PCM 16-bit-le/sample LE data into Opus format.

    Declaration

    Swift

    open func encode(_ audio: UnsafePointer<opus_int16>, frameSize: Int) throws -> [UInt8]

    Parameters

    audio

    A pointer to the audio data. Use maxFrameSize(assumingSize:) to find the length.

    frameSize

    The size of the frame in samples per channel.

    Return Value

    An opus encoded packet.