Created
October 31, 2020 19:26
-
-
Save shiffman/8f08090c49fa4f41cfc36e032c35201e to your computer and use it in GitHub Desktop.
Coding Challenge 80 update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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