xxxxxxxxxx
var mic;
var amp;
var voiceRecognition = new p5.SpeechRec('en-US');
voiceRecognition.onResult = inputspeech;
voiceRecognition.continuous = true;
voiceRecognition.interimResults = true;
var tsize = 40;
var tcolor = "Lime"
var bclor = "Black"
// var tAmplitud= new p5.Amplitud();
function preload() {
theFonts = loadFont('SpaceMono-Regular.ttf');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(bclor);
textSize(amp);
textFont(theFonts);
fill(tcolor);
voiceRecognition.start();
mic= new p5.AudioIn();
mic.start()
}
function draw() {
//ellipse(mouseX, mouseY, 20, 20);
amp = mic.getLevel()*300;
}
function inputspeech() {
background(bclor);
s = voiceRecognition.resultString;
textSize(amp);
text(s, width / 2, height / 2);
textAlign(CENTER);
a = voiceRecognition.resultString.split(' ').pop().toLowerCase();
if (a == 'pink') {
tcolor = fill("PaleGreen");
bclor = color("Pink");
}
if (a == 'yellow') {
tcolor = fill("DarkMagenta");
bclor = color("Gold");
}
if (a == 'blue') {
tcolor = fill("Chocolate");
bclor = color("LightSkyBlue");
}
if (a == 'black') {
tcolor = fill("White");
bclor = color("Black");
}
if(a=='white'){
tcolor= fill("Black");
bclor= color("White");
}
}
// function tSizeChange(){
// if(voiceRecognition<0){
// amplitude = new p5.Amplitude();
// amplitude.setInput(voiceRecognition);
// }
// }