You can use something like the following to access LumenVox from RAGI.
# speech_handler.rb
require 'ragi/call_handler'
module RAGI
# reopen the CallConnection class and add new methods
class CallConnection
#
# returns the name of the calling function or '<unknown>'
#
def callee(back=1)
/in `([a-z_\?\!]+)'/ =~ caller(back).first
"#{$1}" || '<unknown>'
end
#
# call lumenvox applications via asterisk exec, we will raise an exception if it fails
#
# note : classify assumes rails "active_support" is available and loaded
def lumenvox_cmd(func,*params)
var = exec(func.classify, params.join(","))
var = var.to_i
raise "Exception #{var} : running #{func.classify}(#{params.join(",")})" if var < 0
var
end
def speech_start
lumenvox_cmd(callee())
end
def speech_create
lumenvox_cmd(callee())
end
def speech_destroy
lumenvox_cmd(callee())
end
def speech_activate_grammar(grammar)
lumenvox_cmd(callee(),grammar)
end
def speech_deactivate_grammar(grammar)
lumenvox_cmd(callee(),grammar)
end
def speech_background(background)
lumenvox_cmd(callee(),background)
end
end
end
class SpeechHandler < RAGI::CallHandler
# When the RAGI server connects from Asterisk over AGI to our app, it calls this method.
def dialup
answer # answer the call
wait(1) # give it 1 seconds to make sure the connection is established
speech_create
# name of grammar as defined in /etc/asterisk/lumenvox.conf
speech_activate_grammar("grammar")
speech_start
# prompt from sounds directory
speech_background("beep|5") # you could also use "tt-weasels" or add your own
# get the wordslists and score
xml = get_variable("SPEECH_TEXT(0)")
score=get_variable("SPEECH_SCORE(0)")
speech_deactivate_grammar("grammar")
speech_destroy
# process the xml and score as you like
# do some thing with recognized words
rescue
puts $!
ensure
hang_up #end the call
end
end