Created
November 9, 2017 17:48
-
-
Save lizzybrooks/9fef0331cb8960f0898b8da21855b239 to your computer and use it in GitHub Desktop.
This file contains 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
//uses p5.speech.js | |
var myVoice; | |
var sayThis = "Oh hello. I am a computer talking to you."; | |
function setup(){ | |
createCanvas(400, 400); | |
myVoice = new p5.Speech('Google UK English Female'); // new P5.Speech object | |
myVoice.onLoad = speechLoaded; | |
myVoice.onStart = speechStarted; | |
myVoice.onEnd = speechEnded; | |
// speak button: | |
introbutton = createButton('Speak'); | |
introbutton.position(180, 100); | |
introbutton.mousePressed(buttonClicked); | |
} | |
function draw(){ | |
// why draw when you can click? | |
} | |
//when you click the speak button, say the message stored in the variable sayThis. | |
function buttonClicked(){ | |
if(introbutton.elt.innerHTML=='Speak') myVoice.speak(sayThis); | |
else if(introbutton.elt.innerHTML=='Stop') myVoice.stop(); | |
} | |
// say something when the page loads: | |
function speechLoaded(){ | |
myVoice.speak("shall we proceed?"); | |
} | |
//this comes from the library | |
function speechStarted(){ | |
background(0, 255, 0); | |
introbutton.elt.innerHTML = 'Stop'; | |
} | |
//this comes from the library | |
function speechEnded(){ | |
background(255, 0, 0); | |
introbutton.elt.innerHTML = 'Speak'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment