xxxxxxxxxx
//Do something involving speech synthesis, speech recognition, interactive sound, or all three!
//Use the p5.sound and p5.speech libraries in OpenProcessing to create a drum machine,
//or an animation that's driven by voice, or a random music generator,
//or a text game that talks to you, or a speech-based poetry generator,
//or a music visualizer, or an experimental translation tool,
//any other sound- or voice-based interaction that interests you.
//inspired by https://p5js.org/examples/sound-frequency-spectrum.html, https://openprocessing.org/sketch/1288512
var mic, fft
var x
var y
var bar = new p5.SpeechRec('en-US');
bar.onResult = gotspeech;
bar.continuous = true;
bar.interimResults = true;
function setup() {
createCanvas(windowWidth, windowHeight);
mic = new p5.AudioIn();
mic.start();
fft = new p5.FFT();
fft.setInput(mic);
bar.start();
x=540
y=10
}
function draw() {
background(150);
let spectrum = fft.analyze();
beginShape();
for (let i = 0; i < spectrum.length; i++) {
let pitch = map(spectrum[i], -20, 255, height, 0)
vertex(i+554, pitch); // to make the shape in the middle
if(spectrum[i]>200){
background(255)
text("You've reached 200!", 200, 100)
textSize(50)
}
}
endShape();
rect(x, y, 1040, 970)
noFill()
stroke(0)
}
function gotspeech() { //not working haha
s = bar.resultString.split(' ').pop().toLowerCase(); // get the last word you heard
if(s=='up')
{
y-=20
}
if(s=='down')
{
y+=20
}
if(s=='left')
{
x -= 20
}
if(s=='right')
{
x += 20
}
if(s=='clear')
{
x=540
y=10
}
}