1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

pyaudio and nodebox

Posted by Yanone on Sep 25, 2010

hi everyone,

i'm super eager to use nodebox for an interactive illustration. for now i wanted to start with audio input. i went to great lengths to install pyaudio, which seems to be exactly what i need.

here's a code snippet:

import numpy
import pyaudio
import analyse
 
 
speed(1)
 
 
def setup():
    global stream
 
    # Initialize PyAudio
    pyaud = pyaudio.PyAudio()
 
    # Open input stream, 16-bit mono at 44100 Hz
    # On my system, device 2 is a USB microphone, your number may differ.
    stream = pyaud.open(
        format = pyaudio.paInt16,
        channels = 1,
        rate = 44100,
        input = True,
        input_device_index = 2
        )
    
def draw():
    
    global stream
    # Read raw microphone data
    rawsamps = stream.read(1024)
    # Convert raw data to NumPy array
    samps = numpy.fromstring(rawsamps, dtype=numpy.int16)
    # Show the volume and pitch
    print analyse.loudness(samps), analyse.musical_detect_pitch(samps)
similar code used directly from the command line works fine and continuously outputs mic levels in dB, such as -29.7749761525.

calling this code from within nodebox results in an error:
ValueError: input_device_index must be integer (or None)
looking at the code above confirms that input_device_index points indeed to an integer, in this case 2.

my suspicion is now that there's something wrong with nodebox calling all these libraries. i initially had the same library import problems others reported, and solved it by soft-linking python's site-packages folder to nodebox's lib folder.

does anybody know a solution?
thank you very much,
jan


 
Posted by Yanone on Sep 25, 2010

extending my previous question:

I have a bit of a problem to understand what kind of Python Nodebox uses. Digging into the .app package reveals some 2.5 folder structure. Is that the version used by Nodebox? Because I compiled the audio libraries using 10.6's Python 2.6, where also they are located.



Posted by Yanone on Sep 26, 2010

hi there.

i just tried to use a midi controller to read input from knobs and faders on an input device. nodebox now crashes as i touch a button (=midi messages are received).
i even reinstalled all my external libraries for python2.5, but it still crashes.
the same script works fine from the command line.

is there a possibility to completely use the system's python instead of the built-in?

thank you very much