xxxxxxxxxx
var foo;
function setup() {
// speech synthesis object
foo = new p5.Speech();
// function sets callback to fire when synthesis voices are loaded
foo.onLoad = voicesLoaded;
// It is suggested to put everything after the voices are loaded
}
function voicesLoaded(){
// debugging statement
// Lists available synthesis voices to the JavaScript console.
// only works when voices are loaded
foo.listVoices();
// sets synthesizer voice by number (see listVoices()) or by name; equivalent to the default_voice parameter passed with the constructor.
foo.setVoice('Google US English');
// sets the language interpreter for the synthesizer voice.7; Default is 'en-US'
// the default argument is 'en-US'
// this function accepts BCP-4 arguements
// read more about BCP-4 language tags @ https://www.w3.org/International/articles/language-tags/
foo.setLang('en-US');
// sets playback pitch of synthesized speech
// from 0.01 (very low) to 2.0 (very high)
// Default is 1.0; not supported by all browser / OS combinations.
foo.setPitch(1);
// sets rate of speech production
// from 0.1 (very slow) to 2.0 (very fast)
// Default is 1.0; not supported by all browser / OS combinations
foo.setRate(1);
// sets synthesizer volume
// in the range of 0.0 (silent) to 1.0
// default=max volume.
foo.setVolume(1);
// boolean to set whether the speak() method will
// interrupt (true) or queue after (false = default) existing speech currently being synthesiz
foo.interrupt = false;
// ask the synthesis to say something
// instructs the synthesizer to speak the string encoded in utterance.
// Depending on the interrupt property
// additional calls to speak() will queue after or interrupt speech actively being synthesized
// When synthesis begins, the onStart() callback will fire; when synthesis ends, the onEnd() callback will fire.
foo.speak('This is when after voices are loaded.');
}
// function draw(){
// foo.speak('This is put in draw function.');
// }