Skip to content

Commit

Permalink
Merge pull request #228 from Jared-Prime/feature/send_recognition_tim…
Browse files Browse the repository at this point in the history
…eout_to_unimrcp

[Feature] Send recognition timeout to UniMRCP
  • Loading branch information
benlangfeld committed Sep 29, 2014
2 parents 1af904b + e656212 commit dc40e97
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# [develop](https://github.com/adhearsion/punchblock)
* Feature: Support recognition-timeout settings on UniMRCP-based ASR on Asterisk

# [v2.5.3](https://github.com/adhearsion/punchblock/compare/v2.5.2...v2.5.3) - [2014-09-22](https://rubygems.org/gems/punchblock/versions/2.5.3)
* Bugfix: Prevent Asterisk translator death due to dead DTMF recognizers ([#221](https://github.com/adhearsion/punchblock/pull/221), [adhearsion/adhearsion#479](https://github.com/adhearsion/adhearsion/issues/479))
Expand Down
6 changes: 5 additions & 1 deletion lib/punchblock/component/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Input < ComponentNode
# @return [Integer] Indicates (in the case of DTMF input) the amount of time (in milliseconds) between input digits which may expire before a timeout is triggered.
attribute :inter_digit_timeout, Integer

# @return [Integer] Indicates the amount of time during input that recognition will occur before a timeout is triggered.
attribute :recognition_timeout, Integer

attribute :grammars, Array, default: []
def grammars=(others)
super others.map { |other| Grammar.new(other) }
Expand Down Expand Up @@ -65,7 +68,8 @@ def rayo_attributes
'terminator' => terminator,
'sensitivity' => sensitivity,
'initial-timeout' => initial_timeout,
'inter-digit-timeout' => inter_digit_timeout
'inter-digit-timeout' => inter_digit_timeout,
'recognition-timeout' => recognition_timeout
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def validate

raise OptionError, "An initial-timeout value must be -1 or a positive integer." if @initial_timeout < -1
raise OptionError, "An inter-digit-timeout value must be -1 or a positive integer." if @inter_digit_timeout < -1
raise OptionError, "A recognition-timeout value must be -1, 0, or a positive integer." if @recognition_timeout < -1
end

def execute_app(app, *args)
Expand All @@ -48,13 +49,15 @@ def unimrcp_app_options
opts[:spl] = input_node.language if input_node.language
opts[:ct] = input_node.min_confidence if input_node.min_confidence
opts[:sl] = input_node.sensitivity if input_node.sensitivity
opts[:t] = input_node.recognition_timeout if @recognition_timeout > -1
yield opts
end
end

def setup_defaults
@initial_timeout = input_node.initial_timeout || -1
@inter_digit_timeout = input_node.inter_digit_timeout || -1
@recognition_timeout = input_node.recognition_timeout || -1
end

def grammars
Expand Down
13 changes: 13 additions & 0 deletions spec/punchblock/component/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Component
:language => 'en-US',
:initial_timeout => 2000,
:inter_digit_timeout => 2000,
:recognition_timeout => 0,
:sensitivity => 0.5,
:min_confidence => 0.5
end
Expand Down Expand Up @@ -63,6 +64,11 @@ module Component
it { should be == 2000 }
end

describe '#recognition_timeout' do
subject { super().recognition_timeout }
it { should be == 0 }
end

describe '#sensitivity' do
subject { super().sensitivity }
it { should be == 0.5 }
Expand Down Expand Up @@ -118,6 +124,7 @@ module Component
expect(new_instance.language).to eq('en-US')
expect(new_instance.initial_timeout).to eq(2000)
expect(new_instance.inter_digit_timeout).to eq(2000)
expect(new_instance.recognition_timeout).to eq(0)
expect(new_instance.sensitivity).to eq(0.5)
expect(new_instance.min_confidence).to eq(0.5)
end
Expand Down Expand Up @@ -148,6 +155,7 @@ module Component
language="en-US"
initial-timeout="2000"
inter-digit-timeout="2000"
recognition-timeout="0"
sensitivity="0.5"
min-confidence="0.5">
<grammar content-type="application/grammar+custom">
Expand Down Expand Up @@ -204,6 +212,11 @@ module Component
it { should be == 2000 }
end

describe '#recognition_timeout' do
subject { super().recognition_timeout }
it { should be == 0 }
end

describe '#sensitivity' do
subject { super().sensitivity }
it { should be == 0.5 }
Expand Down
39 changes: 39 additions & 0 deletions spec/punchblock/translator/asterisk/component/mrcp_prompt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,45 @@ def expect_app_with_options(app, options)
end
end

describe 'Input#recognition-timeout' do
context 'a positive number' do
let(:input_command_opts) { { recognition_timeout: 1000 } }

it 'should pass the t option to SynthAndRecog' do
expect_synthandrecog_with_options(/t=1000/)
subject.execute
end
end

context '0' do
let(:input_command_opts) { { recognition_timeout: 0 } }

it 'should pass the t option to SynthAndRecog' do
expect_synthandrecog_with_options(/t=0/)
subject.execute
end
end

context 'a negative number' do
let(:input_command_opts) { { recognition_timeout: -1000 } }

it "should return an error and not execute any actions" do
subject.execute
error = ProtocolError.new.setup 'option error', 'A recognition-timeout value must be -1, 0, or a positive integer.'
expect(original_command.response(0.1)).to eq(error)
end
end

context 'unset' do
let(:input_command_opts) { { recognition_timeout: nil } }

it 'should not pass any options to SynthAndRecog' do
expect_synthandrecog_with_options(//)
subject.execute
end
end
end

describe 'Input#inter-digit-timeout' do
context 'a positive number' do
let(:input_command_opts) { { inter_digit_timeout: 1000 } }
Expand Down

0 comments on commit dc40e97

Please sign in to comment.