Example 17 · Anything can be an instrument範例 17 · 什麼都能當樂器

p5 microphonep5 麥克風

micLevel, bass and beat read the microphone the way p5 reads mouseX: a circle that grows when you speak, and no p5.sound.micLevel、bass、beat 像 mouseX 一樣讀麥克風:說話時圓會變大,不用 p5.sound。

Try these three things試試這三件事

  1. Allow the microphone when the browser asks, then talk, clap or play music: the circle grows with how loud it sounds.
  2. A low voice or a bass line turns the colour towards magenta: that is bass.
  3. No microphone? 🎹 → 🥁 starts the drum machine: each kick and snare sets beat, and the ring bursts.
  1. 瀏覽器問的時候允許麥克風,然後說話、拍手或放音樂:圓跟著聽起來多大聲變大。
  2. 低沉的聲音或貝斯,顏色會往紫紅走:那就是 bass。
  3. 沒有麥克風?🎹 → 🥁 開鼓機:每個大鼓、小鼓都讓 beat 變成 true,外圈彈出一圈。

Needs: Microphone.需要:麥克風。 No hardware? Use Drum machine.沒有硬體?用鼓機。

Read these lines讀這幾行

  • sketch.js:17–18 bass and micLevel: 0 to 1, read like mouseX.bass 和 micLevel:0 到 1,像 mouseX 一樣直接讀。
  • sketch.js:19 beat is true for one frame on each beat, like mouseIsPressed.beat 在每個拍子的那一格是 true,像 mouseIsPressed。
  • sketch.js:25 micIsOn: until the microphone runs, say what to do.micIsOn:麥克風開好之前,告訴看的人要做什麼。

In the docs文件裡: The microphone麥克風

Next: 22 p5 lag: smooth a jumpy value →下一個:22 p5 lag:讓跳動的數值變順 → All examples所有範例