Ask Your Question
2

rosrun of a working python script fails

asked 2014-05-12 19:03:39 -0500

Mehdi. gravatar image

I have written a python code using different libraries I already installed (pygame, pyaudio etc...). My script is working very well when I run it using

python myscript.py

but when I put it in my ros package and after making it executable and running it using

rosrun mypackage myscript

it shows some error messages when I click with the mouse and then crashes. Here is the error I get:

    import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9052.
import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9052.
import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9052.
import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9052.
import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9052.
import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9052.
import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9052.
from: can't read /var/mail/std_msgs.msg
import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9052.
import: unable to grab mouse `': Resource temporarily unavailable @ error/xwindow.c/XSelectWindow/9052.
/home/tlili/groovy_workspace/sandbox/BILHR_ros/src/ASR_node.py: line 16: LANG_CODE: command not found
/home/tlili/groovy_workspace/sandbox/BILHR_ros/src/ASR_node.py: line 17: KEY_TLILI: command not found
/home/tlili/groovy_workspace/sandbox/BILHR_ros/src/ASR_node.py: line 18: OTHER_KEY: command not found
/home/tlili/groovy_workspace/sandbox/BILHR_ros/src/ASR_node.py: line 20: GOOGLE_SPEECH_URL: command not found
/home/tlili/groovy_workspace/sandbox/BILHR_ros/src/ASR_node.py: line 21: FLAC_CONV: command not found
/home/tlili/groovy_workspace/sandbox/BILHR_ros/src/ASR_node.py: line 22: INITIAL_SPEECH_THRESHOLD: command not found
/home/tlili/groovy_workspace/sandbox/BILHR_ros/src/ASR_node.py: line 23: FORMAT: command not found
/home/tlili/groovy_workspace/sandbox/BILHR_ros/src/ASR_node.py: line 24: syntax error near unexpected token `('
/home/tlili/groovy_workspace/sandbox/BILHR_ros/src/ASR_node.py: line 24: `SHORT_NORMALIZE = (1.0/32768.0)'

And this is the main part of my script, it basically start saving audio from a microphone when the mouse is clicking on a small black window and when the mouse is released the audio is sent to google speech to text API.

    pa = pyaudio.PyAudio()                                 #]
stream = pa.open(format = FORMAT,                      #|
         channels = CHANNELS,                          #|---- You always use this in pyaudio...
         rate = RATE,                                  #|
         input = True,                                 #|
         frames_per_buffer = INPUT_FRAMES_PER_BLOCK)   #]

speech_threshold = INITIAL_SPEECH_THRESHOLD            #]
noisycount = 0                                         #|---- Variables for noise detector...
quietcount = 0                                         #|
errorcount = 0                                                      #]         
frames = []
isSaving = 0
pygame.init()
pygame.display.set_mode((300,200))
pygame.display.set_caption('Testing')
running = True
#Ros objects to publish strings received after ASR
pub = rospy.Publisher('speech',String)
rospy.init_node('ASR',anonymous=True)
while not rospy.is_shutdown():

    try:                                                    #]
        block = stream.read(INPUT_FRAMES_PER_BLOCK)         #|
    except IOError, e:                                      #|---- just in case there is an error!
        errorcount += 1                                     #|
        print( "(%d) Error recording: %s"%(errorcount,e) )  #|
                                                              #]
    pressed = pygame.mouse.get_pressed()[0]
    if isSaving:
        frames.append(block)
        noisycount += 1
        quietcount = 0
        print(len(frames))
    ev = pygame.event.get()
    for event in ev:
        if event.type == pygame.MOUSEBUTTONDOWN:
            isSaving = 1
            print 'started recording'
        elif event.type ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
9

answered 2014-05-13 01:18:00 -0500

fergs gravatar image

updated 2014-05-13 01:19:05 -0500

It looks like the script is being executed by the shell, not python. Does your script start with a shebang line? Such as:

#!/usr/bin/env python
edit flag offensive delete link more

Comments

Thanks, that solved my problem :D

Mehdi. gravatar imageMehdi. ( 2014-05-13 15:56:42 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-05-12 19:03:39 -0500

Seen: 7,930 times

Last updated: May 13 '14