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) throwsParameters
bitrateThe target bitrate for this encoder.
sampleRateThe sample rate for the encoder. Discord expects this to be 48k.
channelsThe 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
audioA pointer to the audio data. Use
maxFrameSize(assumingSize:)to find the length.frameSizeThe size of the frame in samples per channel.
Return Value
An opus encoded packet.
DiscordOpusEncoder Class Reference