all files / src/ speechkitt.js

81.82% Statements 9/11
50% Branches 6/12
100% Functions 3/3
81.82% Lines 9/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                                                                                                                           
//! Speech KITT
//! version : 0.1.0
//! author  : Tal Ater @TalAter
//! license : MIT
//! https://github.com/TalAter/SpeechKITT
 
(function (undefined) {
  "use strict";
 
  // Save a reference to the global object (window in the browser)
  var _root = this;
 
  // Expose functionality
  _root.SpeechKITT = {
 
    /**
     * Define the function that should be called in order to start speech recognition.
     *
     * #### Examples:
     * ````javascript
     * // Will call annyang's start method
     * SpeechKITT.setStart(annyang.start);
     * // Will call a global function called listen with a local context.
     * SpeechKITT.setStart(listen, this);
     * // Functions can also be stated by name (string)
     * SpeechKITT.setStart('listen', this);
     * // Using the browser's native start function
     * SpeechKITT.setStart(webkitSpeechRecognition.start);
     * ````
     *
     * @param {Function|String} callback - The function to call to start speech recognition
     * @param {Object} [context] - Optional context for the callback function
     * @method setStart
     */
    setStart: function(callback, context) {
      // This should work both when passed a function, or a name of a function
      callback = _root[callback] || callback;
      Eif (typeof callback !== 'function') {
        throw new TypeError('invalid callback function');
      }
      context = context || this;
    },
 
    /**
     * Define the function that should be called in order to abort (stop) speech recognition.
     *
     * #### Examples:
     * ````javascript
     * // Will call annyang's abort method
     * SpeechKITT.setAbort(annyang.abort);
     * // Using the browser's native abort function
     * SpeechKITT.setAbort(webkitSpeechRecognition.abort);
     * ````
     *
     * @param {Function|String} callback - The function to call to abort speech recognition
     * @param {Object} [context] - Optional context for the callback function
     * @method setAbort
     */
    setAbort: function(callback, context) {
      // This should work both when passed a function, or a name of a function
      callback = _root[callback] || callback;
      Eif (typeof callback !== 'function') {
        throw new TypeError('invalid callback function');
      }
      context = context || this;
    }
 
  };
 
}).call(this);