99/**
1010 * p5.speech
1111 * R. Luke DuBois ([email protected] ) 12- * ABILITY Lab / Brooklyn Experimental Media Center
12+ * ABILITY Lab / Integrated Design & Media
1313 * New York University
1414 * The MIT License (MIT).
15- *
15+ *
1616 * https://github.com/IDMNYU/p5.js-speech
1717 *
1818 * Web Speech API: https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html
4545 // objects, which can be cached and re-used for, e.g.
4646 // auditory UI.
4747 //
48- // this implementation assumes a monolithic (one synth,
48+ // this implementation assumes a monolithic (one synth,
4949 // one phrase at a time) system.
5050 //
5151
5757
5858 this . isLoaded = 0 ; // do we have voices yet?
5959
60- // do we queue new utterances upon firing speak()
60+ // do we queue new utterances upon firing speak()
6161 // or interrupt what's speaking:
62- this . interrupt = false ;
62+ this . interrupt = false ;
6363
6464 // callback properties to be filled in within the p5 sketch
6565 // if the author needs custom callbacks:
8181 // onvoiceschanged() fires automatically when the synthesizer
8282 // is configured and has its voices loaded. you don't need
8383 // to wait for this if you're okay with the default voice.
84- //
84+ //
8585 // we use this function to load the voice array and bind our
8686 // custom callback functions.
8787 window . speechSynthesis . onvoiceschanged = function ( ) {
104104
105105 that . utterance . onstart = function ( e ) {
106106 //console.log("STARTED");
107- if ( that . onStart != undefined ) that . onStart ( e ) ;
107+ if ( that . onStart != undefined ) that . onStart ( e ) ;
108108 } ;
109109 that . utterance . onpause = function ( e ) {
110110 //console.log("PAUSED");
116116 } ;
117117 that . utterance . onend = function ( e ) {
118118 //console.log("ENDED");
119- if ( that . onEnd != undefined ) that . onEnd ( e ) ;
119+ if ( that . onEnd != undefined ) that . onEnd ( e ) ;
120120 } ;
121121 }
122122 } ;
230230 p5 . SpeechRec = function ( _lang , _callback ) {
231231
232232 //
233- // speech recognition consists of a recognizer object per
233+ // speech recognition consists of a recognizer object per
234234 // window instance that returns a JSON object containing
235235 // recognition. this JSON object grows when the synthesizer
236236 // is in 'continuous' mode, with new recognized phrases
268268
269269 // continous mode means the object keeps recognizing speech,
270270 // appending new tokens to the internal JSON.
271- this . continuous = false ;
271+ this . continuous = false ;
272272 // interimResults means the object will report (i.e. fire its
273273 // onresult() callback) more frequently, rather than at pauses
274274 // in microphone input. this gets you quicker, but less accurate,
278278 // result data:
279279
280280 // resultJSON:
281- // this is a full JSON returned by onresult(). it consists of a
281+ // this is a full JSON returned by onresult(). it consists of a
282282 // SpeechRecognitionEvent object, which contains a (wait for it)
283283 // SpeechRecognitionResultList. this is an array. in continuous
284- // mode, it will be appended to, not cleared. each element is a
284+ // mode, it will be appended to, not cleared. each element is a
285285 // SpeechRecognition result, which contains a (groan)
286286 // SpeechRecognitionAlternative, containing a 'transcript' property.
287287 // the 'transcript' is the recognized phrase. have fun.
288- this . resultJSON ;
288+ this . resultJSON ;
289289 // resultValue:
290- // validation flag which indicates whether the recognizer succeeded.
290+ // validation flag which indicates whether the recognizer succeeded.
291291 // this is *not* a metric of speech clarity, but rather whether the
292292 // speech recognition system successfully connected to and received
293293 // a response from the server. you can construct an if() around this
294294 // if you're feeling worried.
295- this . resultValue ;
295+ this . resultValue ;
296296 // resultValue:
297297 // the 'transcript' of the most recently recognized speech as a simple
298298 // string. this will be blown out and replaced at every firing of the
299299 // onresult() callback.
300- this . resultString ;
300+ this . resultString ;
301301 // resultConfidence:
302302 // the 'confidence' (0-1) of the most recently recognized speech, e.g.
303303 // that it reflects what was actually spoken. you can use this to filter
304304 // out potentially bogus recognition tokens.
305- this . resultConfidence ;
305+ this . resultConfidence ;
306306
307307 var that = this ; // some bullshit
308308
309309 // onresult() fires automatically when the recognition engine
310310 // detects speech, or times out trying.
311- //
311+ //
312312 // it fills up a JSON array internal to the webkitSpeechRecognition
313- // object. we reference it over in our struct here, and also copy
313+ // object. we reference it over in our struct here, and also copy
314314 // out the most recently detected phrase and confidence value.
315- this . rec . onresult = function ( e ) {
315+ this . rec . onresult = function ( e ) {
316316 that . resultJSON = e ; // full JSON of callback event
317317 that . resultValue = e . returnValue ; // was successful?
318318 // store latest result in top-level object struct
326326 this . rec . onstart = function ( e ) {
327327 if ( that . onStart != undefined ) that . onStart ( e ) ;
328328 } ;
329- // fires on a client-side error (server-side errors are expressed
329+ // fires on a client-side error (server-side errors are expressed
330330 // by the resultValue in the JSON coming back as 'false').
331331 this . rec . onerror = function ( e ) {
332332 if ( that . onError != undefined ) that . onError ( e ) ;
338338
339339 } ; // end p5.SpeechRec constructor
340340
341- // start the speech recognition engine. this will prompt a
342- // security dialog in the browser asking for permission to
341+ // start the speech recognition engine. this will prompt a
342+ // security dialog in the browser asking for permission to
343343 // use the microphone. this permission will persist throughout
344344 // this one 'start' cycle. if you need to recognize speech more
345- // than once, use continuous mode rather than firing start()
345+ // than once, use continuous mode rather than firing start()
346346 // multiple times in a single script.
347347 p5 . SpeechRec . prototype . start = function ( _continuous , _interim ) {
348348 if ( 'webkitSpeechRecognition' in window ) {
@@ -365,6 +365,3 @@ todo:
365365*/
366366
367367// EOF
368-
369-
370-
0 commit comments