talking_watch_sample_en.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>what time)').search(message.lower())
00028 
00029         print 'you said : %s' %message
00030         if time is not None:
00031             d = datetime.datetime.today()
00032             text = 'It\'s %d:%d.' % (d.hour, d.minute)
00033 
00034             # say current time
00035             print 'rospeex reply : %s' %text
00036             self._interface.say(text, 'en', 'nict')
00037 
00038 
00039     def run(self):
00040         """ run ros node """
00041         # initialize ros node
00042         rospy.init_node('ss_sr_demo')
00043 
00044         # initialize rospeex
00045         self._interface.init()
00046         self._interface.register_sr_response(self.sr_response)
00047         self._interface.set_spi_config(language='en',engine='nict')
00048         rospy.spin()
00049 
00050 if __name__ == '__main__':
00051     try:
00052         node = Demo()
00053         node.run()
00054     except rospy.ROSInterruptException:
00055         pass
00056 


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