Go to the documentation of this file.00001
00002
00003
00004
00005 import os
00006 import rospy
00007 from speech_recognition_msgs.msg import Vocabulary
00008 from speech_recognition_msgs.msg import Grammar
00009 from julius_ros.utils import load_grammar
00010
00011
00012 def register_isolated(name, words):
00013 pub = rospy.Publisher("/vocabulary", Vocabulary, queue_size=1)
00014 for i in range(10):
00015 if rospy.is_shutdown() or pub.get_num_connections() > 0:
00016 break
00017 rospy.sleep(1)
00018 rospy.loginfo("Waiting /vocabulary is advertised")
00019 if pub.get_num_connections() == 0:
00020 rospy.logerr("/vocabulary is not advertised")
00021 return
00022 voca = Vocabulary(words=words)
00023 if name:
00024 voca.name = name
00025 pub.publish(voca)
00026
00027
00028 def register_grammar(name, path):
00029 root_dir, name = os.path.dirname(path), os.path.basename(path)
00030 pub = rospy.Publisher("/grammar", Grammar, queue_size=1)
00031 for i in range(10):
00032 if rospy.is_shutdown() or pub.get_num_connections() > 0:
00033 break
00034 rospy.sleep(1)
00035 rospy.loginfo("Waiting /grammar is advertised")
00036 if pub.get_num_connections() == 0:
00037 rospy.logerr("/grammar is not advertised")
00038 return
00039 gram = load_grammar(root_dir, name)
00040 if name:
00041 gram.name = name
00042 pub.publish(gram)