Class: Sphinxtrain::Analyser

Inherits:
Object
  • Object
show all
Defined in:
lib/sphinxtrain/analyser.rb

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Analyser

Returns a new instance of Analyser.



3
4
5
6
# File 'lib/sphinxtrain/analyser.rb', line 3

def initialize(model)
  configuration['hmm'] = model
  configuration['seed'] = 1 # Ensure deterministic results
end

Instance Method Details

#analyse(sentences_file, recordings_dir) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sphinxtrain/analyser.rb', line 8

def analyse(sentences_file, recordings_dir)
  total = 0

  File.open(sentences_file).each_line.with_index do |transcription, index|
    transcription = transcription.downcase.gsub(/[,\.]/, '')
    file_path = File.join(recordings_dir, "arctic_#{(index + 1).to_s.rjust(4, "0")}.raw")
    decoder.decode file_path
    hypothesis = decoder.hypothesis
    error_rate = WordAligner.align(transcription, hypothesis)
    total += error_rate.percentage_accurate

    if block_given?
      yield transcription, hypothesis, error_rate.percentage_accurate
    end
  end

  total / 20
end