Skip to content

Language Settings

Mic Input

Get audio input from your computer's microphone. Make noise to float the ellipse.

Note: p5.AudioIn contains its own p5.Amplitude object, so you can call getLevel on p5.AudioIn without creating a p5.Amplitude.

To run this example locally, you will need the p5.sound library and a running local server.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
let mic;
function setup() {
  createCanvas(710, 200);
  // Create an Audio input
  mic = new p5.AudioIn();
  // start the Audio Input.
  // By default, it does not .connect() (to the computer speakers)
  mic.start();
}
function draw() {
  background(200);
  // Get the overall volume (between 0 and 1.0)
  let vol = mic.getLevel();
  fill(127);
  stroke(0);
  // Draw an ellipse with height based on volume
  let h = map(vol, 0, 1, height, 0);
  ellipse(width / 2, h - 25, 50, 50);
}
X

creative commons license