<commit_before>module AdhearsionCpa
  class ToneDetector

    attr_accessor :tones, :timeout

    def initialize(controller)
      @controller = controller
    end

    def detect_tones(tones, options)
      @tones = tones
      process options

      component.register_event_handler Punchblock::Component::Input::Signal do |event|
        yield event if block_given?
      end if async?

      call.write_and_await_response component if call_alive?

      if async?
        component
      else
        component.complete_event(timeout).reason
      end
    rescue Timeout::Error
      @component.stop! if @component && @component.executing?
      nil
    end

  private

    def process(opts)
      @async   = opts.delete :async
      @timeout = opts.delete :timeout
      opts[:terminate] == false ? opts.delete(:terminate) : opts[:terminate] = true

      @options = opts
    end

    def component
      @component ||= Punchblock::Component::Input.new mode: :cpa, grammars: tone_grammars
    end<commit_msg>[CS] Get component through accessor<commit_after>module AdhearsionCpa
  class ToneDetector

    attr_accessor :tones, :timeout

    def initialize(controller)
      @controller = controller
    end

    def detect_tones(tones, options)
      @tones = tones
      process options

      component.register_event_handler Punchblock::Component::Input::Signal do |event|
        yield event if block_given?
      end if async?

      call.write_and_await_response component if call_alive?

      if async?
        component
      else
        component.complete_event(timeout).reason
      end
    rescue Timeout::Error
      component.stop! if component && component.executing?
      nil
    end

  private

    def process(opts)
      @async   = opts.delete :async
      @timeout = opts.delete :timeout
      opts[:terminate] == false ? opts.delete(:terminate) : opts[:terminate] = true

      @options = opts
    end

    def component
      @component ||= Punchblock::Component::Input.new mode: :cpa, grammars: tone_grammars
    end
{'fraction_non_alphanumeric': 0.08166259168704157, 'fraction_numerical': 0.0, 'mean_word_length': 2.7541284403669724, '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': '6183207', 'n_tokens_mistral': 601, 'n_tokens_neox': 579, 'n_words': 151}