<commit_before>require 'spec_helper'

describe Pocketsphinx::Decoder do
  subject { @decoder }
  let(:configuration) { @configuration }

  # Share decoder across all examples for speed
  before :all do
    @configuration = Pocketsphinx::Configuration.default
    @decoder = Pocketsphinx::Decoder.new(@configuration)
  end

  describe '#decode' do
    it 'correctly decodes the speech in goforward.raw' do
      @decoder.ps_api = nil
      subject.decode File.open('spec/assets/audio/goforward.raw', 'rb')

      expect(subject.hypothesis).to eq("go forward ten meters")
    end

    it 'accepts a file path as well as a stream' do
      subject.decode 'spec/assets/audio/goforward.raw'
      expect(subject.hypothesis).to eq("go forward ten meters")
    end
  end
end<commit_msg>Add integration test for Pocketsphinx::Decoder#words<commit_after>require 'spec_helper'

describe Pocketsphinx::Decoder do
  subject { @decoder }
  let(:configuration) { @configuration }

  # Share decoder across all examples for speed
  before :all do
    @configuration = Pocketsphinx::Configuration.default
    @decoder = Pocketsphinx::Decoder.new(@configuration)
  end

  describe '#decode' do
    it 'correctly decodes the speech in goforward.raw' do
      @decoder.ps_api = nil
      subject.decode File.open('spec/assets/audio/goforward.raw', 'rb')

      expect(subject.hypothesis).to eq("go forward ten meters")
    end

    it 'accepts a file path as well as a stream' do
      subject.decode 'spec/assets/audio/goforward.raw'
      expect(subject.hypothesis).to eq("go forward ten meters")
    end

    it 'reports words with start/end frame values' do
      @decoder.ps_api = nil
      subject.decode File.open('spec/assets/audio/goforward.raw', 'rb')

      expect(subject.words.map(&:word)).to eq(["<s>", "go", "forward", "ten", "meters", "</s>"])
      expect(subject.words.map(&:start_frame)).to eq([608, 611, 623, 676, 712, 771])
      expect(subject.words.map(&:end_frame)).to eq([610, 622, 675, 711, 770, 821])
    end
  end
end
{'fraction_non_alphanumeric': 0.12290227048371175, 'fraction_numerical': 0.017769002961500493, 'mean_word_length': 3.703016241299304, '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': '797475', 'n_tokens_mistral': 680, 'n_tokens_neox': 628, 'n_words': 172}