Hi. I am trying to create a drawing tool that then takes the input from the microphone and applies a visual effect to the drawing in relation to the amplitude of the input.
However I can’t get the microphone to work. I am using processing.py 3 and the Sound library. I am opening with this code but getting 0.0 response in the console when I am playing music…
add_library('sound')
mic = None
amp = None
def setup():
global mic, amp
size(440, 440)
background(0)
mic = AudioIn(this, 2)
mic.start()
amp = Amplitude(this)
amp.input(mic)
def draw():
print(amp.analyze())
Is anyone able to point out where I am going wrong here? Or could you please point me in the right direction for some processing.py sound input examples? Thank you!!
Joe
This is my output with the list and sound on. It seems to be recognising something. But when I try to run the example code from the Getting Started with Processing.py book, I get nada.
device id 0: Default Audio Device
max inputs : 1 (default)
max outputs: 2 (default)
device id 1: BenQ EW3270U
max inputs : 0
max outputs: 2
device id 2: Bose USB Audio
max inputs : 0
max outputs: 6
device id 3: External Headphones
max inputs : 0
max outputs: 2
device id 4: MacBook Pro Microphone
max inputs : 1
max outputs: 0
device id 5: MacBook Pro Speakers
max inputs : 0
max outputs: 2
device id 6: BoomAudio
max inputs : 2
max outputs: 2
device id 7: Port BenQ EW3270U
max inputs : 0
max outputs: 0
device id 8: Port Bose USB Audio
max inputs : 0
max outputs: 0
device id 9: Port External Headphones
max inputs : 0
max outputs: 0
device id 10: Port MacBook Pro Microphone
max inputs : 0
max outputs: 0
device id 11: Port MacBook Pro Speakers
max inputs : 0
max outputs: 0
device id 12: Port BoomAudio
max inputs : 0
max outputs: 0
Code example from the book that isn’t picking up the mic…
add_library('sound')
mic = None
amp = None
def setup():
global mic, amp
size(440, 440)
background(0)
# Create an audio input and start it
mic = AudioIn(this, 0)
mic.start()
# Create a new amplitude analyzer and patch into input
amp = Amplitude(this)
amp.input(mic)
def draw():
# Draw a background that fades to black
noStroke()
fill(26, 76, 102, 10)
rect(0, 0, width, height)
# The analyze() method returns values between 0 and 1,
# so map() is used to convert the values to larger numbers
diameter = map(amp.analyze(), 0, 1, 10, width)
# Draw the circle based on the volume
fill(255)
ellipse(width/2, height/2, diameter, diameter)
However, on Windows, it wouldn’t work initially. I removed the channel argument to default to zero – AudioIn(this) – then saved the sketch. I restarted Processing, then loaded the sketch and it worked fine.