talking_watch_sample.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 try:
00005     import roslib; roslib.load_manifest('rospeex_if')
00006 except:
00007     pass
00008 
00009 import rospy
00010 import datetime
00011 import re
00012 
00013 # Import other libraries
00014 from rospeex_if import ROSpeexInterface
00015 
00016 class Demo(object):
00017     """ Demo class """
00018     def __init__(self):
00019         """ Initializer """
00020         self._interface = ROSpeexInterface()
00021 
00022     def sr_response(self, message):
00023         """ speech recognition response callback
00024         @param message: recognize result (e.g. what time is it ?)
00025         @type  message: str
00026         """
00027         time = re.compile('(?P<time>何時)').search(message)
00028 
00029         print 'you said : %s' % message
00030         if time is not None:
00031             d = datetime.datetime.today()
00032             text = u'%d時%d分です。'%(d.hour, d.minute)
00033 
00034             # rospeex reply
00035             print 'rospeex reply : %s' %text
00036             self._interface.say(text, 'ja', 'nict')
00037 
00038     def run(self):
00039         """ run ros node """
00040         # initialize ros node
00041         rospy.init_node('ss_sr_demo')
00042 
00043         # initialize rospeex
00044         self._interface.init()
00045         self._interface.register_sr_response(self.sr_response)
00046         self._interface.set_spi_config(language='ja',engine='nict')
00047         rospy.spin()
00048 
00049 if __name__ == '__main__':
00050     try:
00051         node = Demo()
00052         node.run()
00053     except rospy.ROSInterruptException:
00054         pass


rospeex_samples
Author(s): Komei Sugiura
autogenerated on Wed Aug 26 2015 16:10:33