xxxxxxxxxx
let mySound;
let y=0;
var volume = 0;
var isSquare = false;
var rec = new p5.SpeechRec('en-US');
rec.onResult = gotSpeech;
rec.continuous = true;
rec.interimResults = true;
var input = '';
function setup() {
rec.start();
x = random(100,900);
createCanvas(windowWidth, windowHeight);
colorMode(HSB);
background(0);
mySound.play();
amplitude = new p5.Amplitude();
y = height;
}
function preload() {
soundFormats('mp3');
mySound = loadSound('BEACH HOUSE -- _LAZULI_ (OFFICIAL MUSIC VIDEO).mp3');
}
function draw() {
noStroke();
let saturation = 0;
let level = amplitude.getLevel();
volume = map(level, 0, 1, 0, 900);
saturation = map(level, 0, 1, 50, 80);
fill(volume, 100, 100);
var brushSize = volume;
background(volume, saturation, 10);
rectMode(CENTER);
if (isSquare == false){
fill(volume, 100, 20);
ellipse(x, y, brushSize*2, brushSize*2);
fill(volume, 100, 50);
ellipse(x, y, brushSize*1.5, brushSize*1.5);
fill(volume, 100, 100);
ellipse(x, y, brushSize, brushSize);
}
else {
fill(volume, 100, 20);
rect(x, y, brushSize*2, brushSize*2);
fill(volume, 100, 50);
rect(x, y, brushSize*1.5, brushSize*1.5);
fill(volume, 100, 100);
rect(x, y, brushSize, brushSize);
}
y = y-1;
if (y < 0) {
y = height;
x=random(100, 900);
}
}
function gotSpeech(){
word = rec.resultString.split(' ').pop().toLowerCase();
if(word =='square')
{
isSquare = true;
}
if(word =='circle')
{
isSquare = false;
}
}