Threading Issue When Using Voice Recognition on TurtleBot3 (Kinetic)

asked 2017-10-18 13:21:04 -0500

jonasro gravatar image

updated 2017-10-21 09:50:28 -0500

I've gotten pocketsphinx (using a wrapper for Kinetic) and pyttsx working on my TurtleBot3. Pocketsphinx seems to be working correctly, but pyttsx stops talking after a single word / phrase. Upon quitting my pyttsx subscriber node I get this error:

^CException in thread /voice (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
  File "/usr/lib/python2.7/threading.py", line 754, in run
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/impl/tcpros_pubsub.py", line 185, in robust_connect_subscriber
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/impl/tcpros_base.py", line 823, in receive_loop
<type 'exceptions.TypeError'>: 'NoneType' object is not callable

The code that we're using subscribes to pocketsphinx topic, and it's pretty generic:

#!/usr/bin/env python

import rospy
import pyttsx
from std_msgs.msg import String


def voice_callback(msg):
    engine = pyttsx.init()
    if 'hello' in msg.data:
        engine.say('Hello, I am Leonardo')
        engine.runAndWait()


def main():
    rospy.init_node('voice')
    sub = rospy.Subscriber('voice', String, voice_callback)
    rospy.spin()

if __name__ == '__main__':
    main()

When the same exact code runs on my VirtualBox, pyttsx can run indefinitely without any problem. Does anyone know why I'm getting this error / how to fix it? Any suggestions and direction will be helpful!

edit retag flag offensive close merge delete