<commit_before>require 'opus-ruby'

# Discord voice chat support
module Discordrb::Voice
  # Wrapper class around opus-ruby
  class Encoder
    attr_accessor :volume, :use_avconv

    def initialize
      @sample_rate = 48_000
      @frame_size = 960
      @channels = 2
      @volume = 1.0
      @opus = Opus::Encoder.new(@sample_rate, @frame_size, @channels)
    end

    def encode(buffer)
      @opus.encode(buffer, 1920)
    end

    def destroy
      @opus.destroy
    end

    def encode_file(file)
      command = "#{ffmpeg_command} -loglevel 0 -i \"#{file}\" -f s16le -ar 48000 -ac 2 #{ffmpeg_volume} pipe:1"
      IO.popen(command)
    end

    def encode_io(io)
      ret_io, writer = IO.pipe
      command = "#{ffmpeg_command} -loglevel 0 -i - -f s16le -ar 48000 -ac 2 #{ffmpeg_volume} pipe:1"
      spawn(command, in: io, out: writer)
      ret_io
    end<commit_msg>Make the opus dependency optional<commit_after>begin
  require 'opus-ruby'
  OPUS_AVAILABLE = true
rescue LoadError
  OPUS_AVAILABLE = false
end

# Discord voice chat support
module Discordrb::Voice
  # Wrapper class around opus-ruby
  class Encoder
    attr_accessor :volume, :use_avconv

    def initialize
      @sample_rate = 48_000
      @frame_size = 960
      @channels = 2
      @volume = 1.0

      if OPUS_AVAILABLE
        @opus = Opus::Encoder.new(@sample_rate, @frame_size, @channels)
      else
        fail LoadError, 'Opus unavailable - voice not supported! Please install opus for voice support to work.'
      end
    end

    def encode(buffer)
      @opus.encode(buffer, 1920)
    end

    def destroy
      @opus.destroy
    end

    def encode_file(file)
      command = "#{ffmpeg_command} -loglevel 0 -i \"#{file}\" -f s16le -ar 48000 -ac 2 #{ffmpeg_volume} pipe:1"
      IO.popen(command)
    end

    def encode_io(io)
      ret_io, writer = IO.pipe
      command = "#{ffmpeg_command} -loglevel 0 -i - -f s16le -ar 48000 -ac 2 #{ffmpeg_volume} pipe:1"
      spawn(command, in: io, out: writer)
      ret_io
    end
{'fraction_non_alphanumeric': 0.10104011887072809, 'fraction_numerical': 0.03467062902426944, 'mean_word_length': 2.568904593639576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4714428', 'n_tokens_mistral': 770, 'n_tokens_neox': 695, 'n_words': 198}