DiscordVoiceFileDataSource

open class DiscordVoiceFileDataSource : DiscordBufferedVoiceDataSource

A subclass of DiscordBufferedVoiceDataSource that buffers a raw audio file.

Usage:

func client(_ client: DiscordClient, needsDataSourceForEngine engine: DiscordVoiceEngine) throws -> DiscordVoiceDataSource {
    return try DiscordVoiceFileDataSource(opusEncoder: try DiscordOpusEncoder(bitrate: 128_000),
                                          file: URL(string: "file://output.raw")!)
}
  • A FileHandle for reading the wrapped file.

    Declaration

    Swift

    public let wrappedFile: FileHandle
  • Sets up a buffered source around a voice file.

    Declaration

    Swift

    public init(opusEncoder: DiscordOpusEncoder,
                file: URL,
                bufferSize: Int = 15_000,
                drainThreshold: Int = 13_500) throws

    Parameters

    opusEncoder

    The Opus encoder to use.

    file

    A file to buffer around.

    bufferSize

    The max number of voice packets to buffer.

    drainThreshold

    The number of packets that must be in the buffer before we start reading more into the buffer.

  • Called when it is time to setup a DispatchIO for reading.

    Override to attach a custom file descriptor. By default it uses wrappedFile.

    Declaration

    Swift

    open override func createDispatchIO()