Step5: Extending the Dialog System¶
Here, we connect our dialog system to the external components.
Edit the script given to the dialog manager as follows.
sample-en2.seatml
<?xml version="1.0" encoding="UTF-8"?> <seatml> <general name="sample"> <agent name="speechin" type="rtcin" datatype="TimedString" /> <agent name="speechout" type="rtcout" datatype="TimedString" /> <agent name="commandout" type="rtcout" datatype="TimedString" /> </general> <state name="OPEN"> <rule> <key>hello</key> <command host="speechout">hello</command> <command host="commandout">command-hello</command> </rule> <rule> <key>bye</key> <command host="speechout">bye bye</command> <command host="commandout">command-bye</command> </rule> </state> </seatml>
Stop the SEAT components (by entering Ctrl + C in the terminal) and start again with the edited script.
% seat sample-en2.seatml
Dialog manager starts with one more output ports.
You can give command to external components by connecting to this port.
For example, we can connect the components shown in the following script.
ConsoleOut.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import time import OpenRTM_aist import RTC consoleout_spec = ["implementation_id", "ConsoleOut", "type_name", "ConsoleOut", "description", "Console output component", "version", "1.0", "vendor", "sample", "category", "example", "activity_type", "DataFlowComponent", "max_instance", "10", "language", "Python", "lang_type", "script", ""] class ConsoleOut(OpenRTM_aist.DataFlowComponentBase): def __init__(self, manager): OpenRTM_aist.DataFlowComponentBase.__init__(self, manager) self._data = RTC.TimedString(RTC.Time(0,0),"") self._inport = OpenRTM_aist.InPort("in", self._data) def onInitialize(self): # Set OutPort buffer self.registerInPort("in", self._inport) return RTC.RTC_OK def onExecute(self, ec_id): while self._inport.isNew(): data = self._inport.read() print "command : %s" % data.data time.sleep(0.1) return RTC.RTC_OK def MyModuleInit(manager): profile = OpenRTM_aist.Properties(defaults_str=consoleout_spec) manager.registerFactory(profile, ConsoleOut, OpenRTM_aist.Delete) comp = manager.createComponent("ConsoleOut") def main(): mgr = OpenRTM_aist.Manager.init(sys.argv) mgr.setModuleInitProc(MyModuleInit) mgr.activateManager() mgr.runManager() if __name__ == "__main__": main()
This component shows the command to the terminal. Please check the received commands, by saying “Hello” “Bye” to the microphone.
By editing the script given to the dialog manager, you can create a port you like and send data of any type. By using this feature, for example, you can connect the dialog system to the actual robot to send command “moving forward” or “retreat”.