Search code examples
javascriptxmlv8freeswitchspidermonkey

FreesWitch speech recognition speechtools.jm Error


i am trying to use freesWitch but headed with this error . can sombody help how i can resolve this ? i do get the xml but it can't parse it accordingly

<result grammar="pizza_order">
  <interpretation grammar="pizza_order" confidence="100">
    <input mode="speech">delivery</input>
  </interpretation>
</result>

the point where i am stuck is , i need to parse xml each attribute and each node but i am unable to use dom parser aswel, the only reference i got was

https://freeswitch.org/confluence/display/FREESWITCH/JavaScript+example+-+XML#JavaScriptexample-XML-Examples

but i almost tried everything but cannot get the data out of that XML , kindly help me to get parse this small XML successfully or any simple logic which doesn't use any parser in javascript will also work , i have this xml in string aswel. Thanks


Solution

  • var input1 = xml.getChild('interpretation');
    
    var input2 = input1.getChild('input');
    console_log('info', 'XML newChild attrbute firstattr: ' + input1.getAttribute('grammar'));
    
    
    
                                                    var score = input1.getAttribute('confidence');
                                                    var child = xml.getChild('result');
    
    
    
                                                    var ahsan = xml.serialize();
                                                    console_log('info', 'Full XML ::\n' + ahsan +  " method=" + input2.data  );
                                                    console_log("debug", "----XML---> :\n" + body + "\n");
    
    
                                                    console_log("debug", "----Hit score [" + score + "]/" +
                                                    grammar_object.min_score + "/" + grammar_object.confirm_score + "\n");
    

    I think it will solve your problem