xxxxxxxxxx
48
//quick example of how to listen for some sounds and play sounds when they trigger.
//let socket = io("https://pvtmsockets.glitch.me/");
let myRec = new p5.SpeechRec(); // new P5.SpeechRec object
let listening=["bark","restaurant", "chips", "genie"]
let images=["",]
let sounds=[];
function preload() {
// Initialize sound
sounds[0] = loadSound("https://cdn.glitch.global/0261e287-6ea5-4c9d-af51-af9d7a9bf717/dog.wav?v=1687745676865");
sounds[1] = loadSound("https://cdn.glitch.global/0261e287-6ea5-4c9d-af51-af9d7a9bf717/restaurant.wav?v=1687745677216");
sounds[2] = loadSound("https://cdn.glitch.global/0261e287-6ea5-4c9d-af51-af9d7a9bf717/chips.wav?v=1687745676614");
sounds[3] = loadSound("https://cdn.glitch.global/0261e287-6ea5-4c9d-af51-af9d7a9bf717/magic.wav?v=1687746384630");
}
function setup() {
createCanvas(windowWidth,windowHeight);
// SpeechRec callback
myRec.onResult = showResult;
myRec.continuous=true;
myRec.interimResults=true
myRec.start();
textAlign(CENTER, CENTER);
textSize(12);
}
function showResult() {
if (myRec.resultValue == true) {
background(255);
text(myRec.resultString, width / 2, height / 2);
for (let i =0;i<listening.length;i++){
let rec=myRec.resultString.toLowerCase()
if(rec.includes(listening[i].toLowerCase())){
console.log("Match: "+listening[i]);
if(!sounds[i].isPlaying()){
sounds[i].play();
}
}
}
console.log(myRec.resultString);
}
}
function mousePressed() {
userStartAudio();
}