Upgrade 3CX to v18 and get it hosted free!

Using LumenVox with RAGI

Author image

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


Article Reviews

Write a Review

Your email address will not be published. Required fields are marked *

Required Field. Minimum 5 characters.

Required Field. Minimum 5 characters, maximum 50.

Required field.There is an error with this field.

Required Field.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

There are no reviews for this article. Be the first one to write a review.
Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.