-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathdecoder_spec.rb
More file actions
51 lines (41 loc) · 1.84 KB
/
decoder_spec.rb
File metadata and controls
51 lines (41 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'spec_helper'
describe Pocketsphinx::Decoder do
subject { @decoder }
let(:configuration) { @configuration }
# Share decoder across all examples for speed
before do
@configuration = Pocketsphinx::Configuration.default
@decoder = Pocketsphinx::Decoder.new(@configuration)
end
it 'reads cmninit configuration values from default acoustic model feat.params' do
expect(configuration.details('cmninit')[:default]).to eq("8.0")
expect(configuration.details('cmninit')[:value]).to eq("40,3,-1")
end
describe '#decode' do
it 'correctly decodes the speech in goforward.raw' do
subject.decode File.open('spec/assets/audio/goforward.raw', 'rb')
expect(subject.hypothesis).to eq("go forward ten meters")
expect(subject.hypothesis.path_score).to eq(-7636)
expect(subject.hypothesis.posterior_prob).to eq(0.4659446069409511)
end
# FIXME: This test illustrates a current issue discussed in:
# https://github.com/watsonbox/pocketsphinx-ruby/issues/10
it 'incorrectly decodes the speech in hello.wav on first attempt' do
hypotheses = (1..2).map do
subject.decode File.open('spec/assets/audio/hello.wav', 'rb')
subject.hypothesis
end
expect(hypotheses).to eq(['oh', 'hello'])
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
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([0, 46, 64, 117, 153, 212])
expect(subject.words.map(&:end_frame)).to eq([45, 63, 116, 152, 211, 260])
end
end
end