# Python Sound Library

**URL:** <https://discourse.processing.org/t/python-sound-library/35034>\
**Category:** Processing.py\
**Created:** [February 8, 2022, 12:14am UTC](https://discourse.processing.org/t/python-sound-library/35034 "2022-02-08T00:14:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_Math\_Maniac1](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@The\_Math\_Maniac1](https://discourse.processing.org/u/The_Math_Maniac1)\
**Post date:** [February 8, 2022, 12:14am UTC](https://discourse.processing.org/t/python-sound-library/35034/1 "2022-02-08T00:14:09Z")

</div>

Hey, I am just starting to look into using sound in processing more seriously, and it seems that the best way is with the Processing Foundation Sound library. But I am running into an issue with it. I run my code, and it will not give me any errors or information, it will just run and not do anything. Right now my code is this:

```auto
add_library("sound")
def setup():
    global input
    global loudness
    size(1080, 1080)
    input = AudioIn(this, 0)
    input.start()
    loudness = Amplitude(this)
    loudness.input(input)
def draw():
    global input
    global loudness
    inputLevel = map(mouseY, 0, height, 1.0, 0.0);
    input.amp(inputLevel)
    volume = loudness.analyze()
    sizen = int(map(volume, 0, 0.5, 1, 350))
    circle(width/2, height/2, sizen)

```

But when I run it I get a circle with a size of 1 (presumably), and when I print the volume variable, it just returns a constant 0.0. If I print the sizen variable, it returns a constant 1. I don’t know what I am doing wrong or if I’m even doing anything wrong at all. All I do know is that this is running on Windows 10 and processing 3.5.4. If anyone can help that would be wonderful. If there’s any information that you need I’ll try to get it for you.

---

<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:** [February 8, 2022, 10:20pm UTC](https://discourse.processing.org/t/python-sound-library/35034/2 "2022-02-08T22:20:06Z")

</div>

I copy-pasted this into Processing 3.5.4 for Windows and Linux – the sketch works fine for me. Are you certain your mic is working correctly? Have you tested it in another application (to see if it’s picking up any sound)?

---

<div class="post-metadata">

**Author:** ![The\_Math\_Maniac1](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@The\_Math\_Maniac1](https://discourse.processing.org/u/The_Math_Maniac1)\
**Post date:** [February 8, 2022, 11:44pm UTC](https://discourse.processing.org/t/python-sound-library/35034/3 "2022-02-08T23:44:16Z")

</div>

I have tested it in Java mode, using the example code for the sound library and it worked exactly as I expected, so processing is picking up on the audio for sure. This code is just my copy of the code over to python to test.

---

<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:** [February 9, 2022, 12:49am UTC](https://discourse.processing.org/t/python-sound-library/35034/4 "2022-02-09T00:49:26Z")

</div>

Sometimes restarting Processing helps with odd things like this – like, switch to Python Mode, quit Processing, restart (Python Mode is now default) and try run the code again. There’s always the ol’ Windows turn-it-off-and-on-again thing, too …

Sorry, that’s all I can suggest.

---

<div class="post-metadata">

**Author:** ![The\_Math\_Maniac1](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@The\_Math\_Maniac1](https://discourse.processing.org/u/The_Math_Maniac1)\
**Post date:** [February 10, 2022, 12:05am UTC](https://discourse.processing.org/t/python-sound-library/35034/5 "2022-02-10T00:05:09Z")

</div>

After not running the file for a while, it just suddenly started working properly, thank you!

---

<div class="post-metadata">

**Author:** ![The\_Math\_Maniac1](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@The\_Math\_Maniac1](https://discourse.processing.org/u/The_Math_Maniac1)\
**Post date:** [February 10, 2022, 12:27am UTC](https://discourse.processing.org/t/python-sound-library/35034/6 "2022-02-10T00:27:50Z")

</div>

Actually, after more testing, it runs properly the first time, then any time after that I have to relaunch processing ☹

---

<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:** [February 28, 2022, 9:10pm UTC](https://discourse.processing.org/t/python-sound-library/35034/7 "2022-02-28T21:10:43Z")

</div>

Hardly an ideal solution, but thanks @The_Math_Maniac1 for noting how you got it working.
