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


rospeex_samples
Author(s): Komei Sugiura
autogenerated on Thu Apr 20 2017 03:09:00