<commit_before>class RecordingServer
  def initialize
    # Test to ensure that sox is installed
    result = `which sox`
    raise 'Please install sox using an appropriate package manager' if result.empty?
  end

  def start_recording
    filename = 'sample.wav'
    seconds_sample = 10

    system "rm -f #{filename}"
    system "rec -c 2 #{filename} trim 0 #{seconds_sample}"
    output = `sox #{filename} -n stat 2>&1 | grep "Maximum amplitude" | awk '{printf $3}'`

    max_amp = output.to_f
    system "rm -f #{filename}"

    #max_amp < 0.1? false : true
    "Result: #{max_amp}"
  end
end<commit_msg>Changes so that recording will work on a Linux box that doesn't have the analog device as the first / default option.<commit_after>class RecordingServer
  def initialize
    # Test to ensure that sox is installed
    result = `which sox`
    raise 'Please install sox using an appropriate package manager' if result.empty?
  end

  def start_recording
    filename = 'sample.wav'
    seconds_sample = 10

    system "rm -f #{filename}"

    begin
      # Test to see if the box this is running on has aplay installed
      output = `aplay -l | grep -A 2 Analog`
      matches = output.gsub("\n", '').match(/card (\d+):.*Subdevice #(\d+):/)
      soundcard = "AUDIODRIVER=alsa AUDIODEV=hw:#{matches[1]},#{matches[2]}"
    rescue
      # Do nothing, just catch the error
    end
    system "#{soundcard} rec -c 2 #{filename} trim 0 #{seconds_sample}"
    output = `sox #{filename} -n stat 2>&1 | grep "Maximum amplitude" | awk '{printf $3}'`

    max_amp = output.to_f
    system "rm -f #{filename}"

    #max_amp < 0.1? false : true
    "Result: #{max_amp}"
  end
end
{'fraction_non_alphanumeric': 0.11708482676224612, 'fraction_numerical': 0.012544802867383513, 'mean_word_length': 3.036144578313253, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6677689', 'n_tokens_mistral': 549, 'n_tokens_neox': 521, 'n_words': 197}