.. _speech_command_proposer: Speech Command Proposer ======================= The Speech-Command-Proposer can make suggestions on what to say to the dialog-system in the apartment. It is capable of managing active rules, give random examples for rules and sending them as a `DialogAct`_. The :ref:`speech_visualizer` holds a visualization for the Speech-Command-Proposer, the GrammarHelper. Related resources ----------------- Related projects: - :ref:`speech_visualizer` - :ref:`jsgf_parser` Component repository: - Browse component repository: `dialog-helper `_. - ``git clone http://projects.cit-ec.uni-bielefeld.de/git/agaispeechprocessing.git.dialog-helper.git`` System startup: The start script speech-command-proposer.sh can be found at ``/vol/csra//releases/trusty/lsp-csra-nightly/opt/speech-command-proposer/bin/speech-command-proposer.sh``. The program can be invoked with the following parameters: -g , --grammar The grammar that should be inspected. -s , --scope Set the scope on which remote-calls can be invoked. Interfaces ---------- Input/Output: | This tool provides various methods for remote-calls. | The property of ``-s`` or ``--scope`` serves as prefix. | =========================================== ===================== ========================== Scope (Local Server) + Method Argument Type Return Type =========================================== ===================== ========================== ``prefix/setGrammar()`` String Boolean ``prefix/getGrammarPath()`` String ``prefix/getActiveRules()`` `Value`_ ``prefix/setActiveRules()`` `Value`_ ``prefix/setAllRulesActive()`` ``prefix/getExampleForRule()`` String String ``prefix/sendDA()`` String Boolean ``prefix/setDaScope()`` String String ``prefix/getRuleDicts()`` `DictionaryCollection`_ removed since 1.3 ``prefix/getAllRules()`` `Value`_ ``prefix/getRuleByDepthMap()`` Int `Dictionary`_ =========================================== ===================== ========================== =========================================== ======================================== Scope (Informer) Type =========================================== ======================================== ``prefix/grammarhelper/rulechange`` String ``serverMethod/setDaScope()`` `DialogAct`_ =========================================== ======================================== - setGrammar returns whether setting the grammar was successful or not. - sent values (argument and return type) are from type array which are holding strings. - the rule-change-informer triggers whenever the active-rule-list or grammar is changed and sends a redundant string to :ref:`grammar_helper`. - the dialogact-informer is triggered by servermethod sendDA(). .. _Value: http://docs.cor-lab.de//rst-manual/0.14/html/generated/stable/package-rst-generic.html#rst.generic.Value .. _DialogAct: http://docs.cor-lab.de//rst-manual/0.15/html/generated/stable/package-rst-dialog.html#rst.dialog.DialogAct .. _Dictionary: http://docs.cor-lab.de//rst-manual/0.15/html/generated/stable/package-rst-generic.html#rst.generic.Dictionary .. _DictionaryCollection: http://docs.cor-lab.de//rst-manual/0.15/html/generated/stable/package-rst-generic.html#rst.generic.DictionaryCollection Example -------- With the speech-command-proposer up running, you can call methods from another tool. About active rules: * all rules are active by default. * setting a list of active rules will overwrite the previous list of active rules. .. code-block:: java :emphasize-lines: 10,11,14,15,21,22,25,26,27,28,30,50,51,60,65,67,68,72,73,78,79 Value.Builder stringBuilder = ValueType.Value.newBuilder().setType(ValueType.Value.Type.STRING); Value.Builder arrBuilder = ValueType.Value.newBuilder().setType(ValueType.Value.Type.ARRAY); try { final RemoteServer server = Factory.getInstance().createRemoteServer( "/exampleRsbScope"); server.activate(); try { //retrieve current used grammar-path Event gramCheck = server.call("getGrammarPath"); System.out.println(gramCheck.getData().toString()); //set scope for sending dialogacts server.call("setDaScope", "/scopeForDialogActs"); //we need a list for the rules. List l = new LinkedList(); //set a grammar Object gramCall = server.call("setGrammar", "./example.gram"); Boolean grBool = Boolean.valueOf(gramCall.toString()); System.out.println("setting grammar successful: " + grBool); if (grBool) { //call server-method getRuleDicts DictionaryCollectionType.DictionaryCollection dc = (DictionaryCollectionType.DictionaryCollection) server.call("getRuleDicts"); //each dictionary is a representation for one rule for (Dictionary d : dc.getElementList()) { //there are three different keys for the key-value-pairs String ruleName = ""; String example = ""; long depth = 0; boolean active; for (KeyValuePair kvp : d.getEntriesList()) { switch (kvp.getKey()) { case "rule": ruleName = kvp.getValue().getString(); System.out.println("\t" + kvp.getKey() + " " + ruleName); break; case "example": example = kvp.getValue().getString(); System.out.println("\t" + kvp.getKey() + " " + example); break; case "active": active = kvp.getValue().getBool(); System.out.println("\t" + kvp.getKey() + " " + String.valueOf(active)); break; } //send an dialogact for each rule in the collection server.call("sendDA", ruleName + ";" + example); //we want to have all rules active, //so we fill the list with them here. l.add(ruleName); } } //set a list of active rules for (String s : l) { Value value1 = stringBuilder.setString(s).build(); arrBuilder.addArray(value1); } server.call("setActiveRules", new Event(Value.class, arrBuilder.build())); //call server for active rules Event ruleCall = server.call("getActiveRules"); Value v = (Value) ruleCall.getData(); for (Value va : v.getArrayList()) { String rule = va.getString(); //call server for example Object exampleCall = server.call("getExampleForRule", rule); System.out.println("exampleCall for rule: " + rule + ": " + exampleCall.toString()); } //set all rules back to active server.call("setAllRulesActive"); } } } catch (ExecutionException | TimeoutException | InterruptedException ex) { Logger.getLogger(TestProject.class.getName()).log(Level.SEVERE, null, ex); } finally { try { server.deactivate(); } catch (InterruptedException ex) { Logger.getLogger(TestProject.class.getName()).log(Level.SEVERE, null, ex); } } } catch (RSBException ex) { Logger.getLogger(TestProject.class.getName()).log(Level.SEVERE, null, ex); }