Skip to content

Instantly share code, notes, and snippets.

@shiffman
Created October 31, 2020 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiffman/8f08090c49fa4f41cfc36e032c35201e to your computer and use it in GitHub Desktop.
Save shiffman/8f08090c49fa4f41cfc36e032c35201e to your computer and use it in GitHub Desktop.
Coding Challenge 80 update
function setup() {
noCanvas();
let button = createButton('start');
button.mousePressed(function() {
let speech = new p5.Speech();
let speechRec = new p5.SpeechRec('en-US', gotSpeech);
let continuous = true;
let interim = false;
speechRec.start(continuous, interim);
let bot = new RiveScript();
loadBot();
async function loadBot() {
await bot.loadFile('brain.rive');
bot.sortReplies();
}
async function gotSpeech() {
if (speechRec.resultValue) {
let input = speechRec.resultString;
let reply = await bot.reply('local-user', input);
console.log(reply);
speech.speak(reply);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment