-
Notifications
You must be signed in to change notification settings - Fork 0
/
speech_listener.py
42 lines (33 loc) · 1.05 KB
/
speech_listener.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
# coding=utf-8
import rospy
# from std_msgs.msg import Bool
from std_msgs.msg import UInt16
from speech_recognition_msgs.msg import *
from speech_recognition_msgs.srv import *
def cb(msg):
pub = rospy.Publisher('speech', UInt16)
uint16_msg = UInt16()
rospy.loginfo(msg.transcript[0])
if msg.transcript[0] in ["上がれ", "暴れ", "剥がれ", "agar", "流れ"]:
print("上がれ")
uint16_msg.data = 1
pub.publish(uint16_msg)
elif msg.transcript[0] == "下がれ":
print("下がれ")
uint16_msg.data = 2
pub.publish(uint16_msg)
def main():
rospy.init_node('speech_listener', anonymous=True)
rospy.Subscriber("/Tablet/voice", SpeechRecognitionCandidates, cb)
rospy.loginfo("Setting up vocabulary ... ")
try:
rospy.loginfo("good")
except rospy.ServiceException, e:
print("Service call failed: %s"%e)
rospy.loginfo("OK")
rate = rospy.Rate(10)
rospy.spin()
rate.sleep()
if __name__ == '__main__':
main()