# Using Sound Input From Mic

**URL:** <https://discourse.processing.org/t/using-sound-input-from-mic/21448>\
**Category:** Processing.py\
**Created:** [May 31, 2020, 10:02am UTC](https://discourse.processing.org/t/using-sound-input-from-mic/21448 "2020-05-31T10:02:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![joebrailsford](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joebrailsford](https://discourse.processing.org/u/joebrailsford)\
**Post date:** [May 31, 2020, 10:02am UTC](https://discourse.processing.org/t/using-sound-input-from-mic/21448/1 "2020-05-31T10:02:51Z")

</div>

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…

```auto
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

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [May 31, 2020, 10:24am UTC](https://discourse.processing.org/t/using-sound-input-from-mic/21448/2 "2020-05-31T10:24:13Z")

</div>

Welcome, @joebrailsford!

Your code works fine on my system.

Have you tried different channel arguments? Like:  
`mic = AudioIn(this, 0)`  
or  
`mic = AudioIn(this, 1)`

What output do you get if you run this line?  
`print(Sound.list())`

---

<div class="post-metadata">

**Author:** ![joebrailsford](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joebrailsford](https://discourse.processing.org/u/joebrailsford)\
**Post date:** [May 31, 2020, 11:11am UTC](https://discourse.processing.org/t/using-sound-input-from-mic/21448/3 "2020-05-31T11:11:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joebrailsford](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joebrailsford](https://discourse.processing.org/u/joebrailsford)\
**Post date:** [May 31, 2020, 11:11am UTC](https://discourse.processing.org/t/using-sound-input-from-mic/21448/4 "2020-05-31T11:11:44Z")

</div>

Code example from the book that isn’t picking up the mic…

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![joebrailsford](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joebrailsford](https://discourse.processing.org/u/joebrailsford)\
**Post date:** [May 31, 2020, 11:12am UTC](https://discourse.processing.org/t/using-sound-input-from-mic/21448/5 "2020-05-31T11:12:39Z")

</div>

And thanks! Great to be here 🙂 I’m excited to embark on this audio visual journey!

---

<div class="post-metadata">

**Author:** ![joebrailsford](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joebrailsford](https://discourse.processing.org/u/joebrailsford)\
**Post date:** [May 31, 2020, 12:13pm UTC](https://discourse.processing.org/t/using-sound-input-from-mic/21448/7 "2020-05-31T12:13:19Z")

</div>

Hmmm sadly that didn’t make the circles start dancing…

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [May 31, 2020, 12:58pm UTC](https://discourse.processing.org/t/using-sound-input-from-mic/21448/8 "2020-05-31T12:58:43Z")

</div>

Okay – this worked fine on my Linux machine.

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.

Maybe you could try this, too.

---

<div class="post-metadata">

**Author:** ![joebrailsford](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@joebrailsford](https://discourse.processing.org/u/joebrailsford)\
**Post date:** [June 3, 2020, 11:25am UTC](https://discourse.processing.org/t/using-sound-input-from-mic/21448/9 "2020-06-03T11:25:37Z")

</div>

Hey.

I have tried closing, saving, changing input, reverting to default and nada…

Very strange.

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [June 7, 2020, 9:22am UTC](https://discourse.processing.org/t/using-sound-input-from-mic/21448/10 "2020-06-07T09:22:26Z")

</div>

Okay –

I tried this on a MacBook running High Sierra; it worked fine. Then I tried an iMac running Catalina, and it didn’t work. Are you running Catalina?

After a quick search, I found this:

> [@Give Mic access to Processing Sketch (Mac Catalina)](https://discourse.processing.org/t/give-mic-access-to-processing-sketch-mac-catalina/17953):
>
> I/m looking for a way to give my sketch access to my mic in Mac Catalina. I know you can manage your mic access in the System Preferences, but I can’t manually add apps. I already found this link: [macOS Mojave and Catalina TCC trigger](https://github.com/processing/processing-sound/issues/5) where they talk about Processing not asking for permission (mic and cam) when needed, but after reading everything 6 times I have NO idea what they are talking about. It seems like they offer a work-around, but I’m really not sure how or where to implement. So, i…
