Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] pyaudio error in inline script

edited April 2014 in OpenSesame

HI all,
Can you help me correct my experiment?
I'm getting the following message when my experiment runs.

Error while executing inline script
phase: run
item: _inline_script
line: 442
exception message: 
exception type: IOError

Traceback (also in debug window):
  File "dist\libopensesame\inline_script.py", line 154, in run
  File "", line 45, in 
  File "pyaudio.pyo", line 747, in open
  File "pyaudio.pyo", line 442, in __init__
IOError: [Errno Device unavailable] -9985

I dont know what the problem is.
Help Please!
Thanks.

Comments

  • edited 3:46PM

    According to the error message, you seem to be experiencing a problem in line 442 of an inline_script item called _inline_script. This problem originates from your use of the pyaudio module. It seems the device you are trying to use does not exist. These kind of things can happen e.g. when you use incorrect port numbers.

    Without further information we cannot provide any further help. Further information that would be useful is the specific inline_script (although with at least 442 lines, I hope a snippet of your code will suffice).

    Good luck!

  • edited April 2014

    Thank you for replying, Edwin
    This is the full inline_script that I used.

    """
    This example listens for a sound from the microphone.
    It has been adapted from:
    http://stackoverflow.com/questions/4160175/detect-tap-with-pyaudio-from-live-mic
    """
    
    # Measure the start of the response interval
    start_response_interval = self.time()
    
    import pyaudio
    
    TAP_THRESHOLD = 0.050
    FORMAT = pyaudio.paInt16 
    SHORT_NORMALIZE = (1.0/32768.0)
    CHANNELS = 2
    RATE = 44100  
    INPUT_BLOCK_TIME = 0.01
    INPUT_FRAMES_PER_BLOCK = int(RATE*INPUT_BLOCK_TIME)
    
    def get_rms( block ):
    
        """Get root mean square as a measure of loudness"""
    
        import struct
        import math 
    
        global SHORT_NORMALIZE
    
        count = len(block)/2
        format = "%dh" % (count)
        shorts = struct.unpack( format, block )
        sum_squares = 0.0
        for sample in shorts:
            n = sample * SHORT_NORMALIZE
            sum_squares += n*n
        return math.sqrt( sum_squares / count )
    
    # Open the mic
    stream = pyaudio.PyAudio().open(format = FORMAT,
        channels = CHANNELS,
        rate = RATE,
        input = True,
        input_device_index = 0,
        frames_per_buffer = INPUT_FRAMES_PER_BLOCK)
    
    # Listen until a sound has been detected
    while True:
        try:
            block = stream.read(INPUT_FRAMES_PER_BLOCK)
        except IOError, e:
            print e
        loudness = get_rms( block )
        if loudness > TAP_THRESHOLD:
            break
    
    self.experiment.set("response_time", self.time() - start_response_interval)
    self.experiment.set("loudness", loudness)
    
    # Close the mic
    stream.close()
    
    

    I'm still experiencing problems.
    Help please.
    Thanks guys!

  • edited April 2014

    Couple of questions:

    1) Is this the entire inline_script named "_inline_script"? Why did the previous error state an error in line 442? (clearly, this script is shorter: could it be that you have some leftover script in the unused items?)

    2) Are you sure there is a microphone attached? If yes: is the mic not accessed by any other piece of software? This seems to be a silly question, but your script looks fine, and your error indicates that there is no available device. So double-checking this is important!

    BTW: I just tested your code (using OpenSesame 2.8.0 on Ubuntu 12.04), and it runs fine. This means that it's likely not a problem with your script, but with your setup.

Sign In or Register to comment.