Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!doctype html>
<html>
<head>
  <script src="https://cdn.pubnub.com/pubnub-3.15.1.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
  <script src="https://cdn.pubnub.com/sdk/pubnub-angular/pubnub-angular-3.2.1.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
  <script src="https://cdglabs.github.io/ohm/dist/ohm.js"></script>
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" />
</head>
<body>
<div class="container" ng-app="PubNubAngularApp" ng-controller="MySpeechCtrl">

<pre>NOTE: make sure to update the PubNub keys below with your keys!</pre>
  
<h3>MyVoice to Commands</h3>

<pre>
  KNOWN COMMANDS:

  "set timer for 45 minutes"
  "set alarm for 5 o'clock"
  "what time is it"
</pre>

<input type="button" ng-click="dictateIt()" value="Speak a Command" />

<br /><br />
  
<ul>
  <li ng-repeat="command in commands track by $index">
    {{command.text}}
    <a ng-click="handleIt(command)">(handle again)</a>
  </li>
</ul>

</div>
<script type="text/ohm-js">
// An Ohm grammar for parsing voice commands
COMMAND {
  command       = timer_cmd | alarm_cmd | time_isit_cmd
  timer_cmd     = "set timer for " number " minutes"
  alarm_cmd     = "set alarm for " number " o'clock"
  time_isit_cmd = "what time is it"
  number        = digit+
}
</script>
<script>
var gram = ohm.grammarFromScriptElement();
var sem  = gram.semantics().addOperation('toList',{
  number:        function(a)            { return parseInt(this.interval.contents,10); },
  timer_cmd:     function(_, number, _) { return ['timer_cmd', number.toList(), " minutes"]; },
  alarm_cmd:     function(_, hour, _)   { return ['alarm_cmd', hour.toList(), " o'clock"]; },
  time_isit_cmd: function(x)            { return ['time_isit_cmd']; },
  command:       function(x)            { return {text:this.interval.contents, cmd:x.toList()}; }
});

angular.module('PubNubAngularApp', ["pubnub.angular.service"])
.controller('MySpeechCtrl', function($rootScope, $scope, Pubnub) {
  $scope.commands     = [{text:"no commands yet"}];
  $scope.msgChannel   = 'MySpeech';

  if (!$rootScope.initialized) {
    Pubnub.init({
      publish_key: 'YOUR_PUB_KEY',
      subscribe_key: 'YOUR_SUB_KEY',
      ssl:true
    });
    $rootScope.initialized = true;
  }

  var msgCallback = function(payload) {
    $scope.$apply(function() {
      $scope.commands.push(payload);
    });
    $scope.handleIt(payload);
  };

  Pubnub.subscribe({ channel: [$scope.msgChannel, $scope.prsChannel], message: msgCallback });

  $scope.handleIt = function (command) {
    if (command.cmd && command.cmd[0] === "time_isit_cmd") {
      window.speechSynthesis.speak(new SpeechSynthesisUtterance("the current time is " + (new Date()).toISOString().split("T")[1].split(".")[0]));
    } else if (command.cmd) {
      window.speechSynthesis.speak(new SpeechSynthesisUtterance("okay, got it - I will " + command.text));
    } else {
      window.speechSynthesis.speak(new SpeechSynthesisUtterance("I'm not quite sure about that"));
    }
  };
  
  $scope.dictateIt = function () {
    var theText = "";
    var recognition = new webkitSpeechRecognition();
    recognition.onresult = function (event) {
      for (var i = event.resultIndex; i < event.results.length; i++) {
        if (event.results[i].isFinal) {
          theText  += event.results[i][0].transcript;
        }
      }

      var match  = gram.match(theText.toLowerCase());
      var result = match.succeeded() ? sem(match).toList() : {text:theText};

      Pubnub.publish({
        channel: $scope.msgChannel,
        message: result
      });
    };
    recognition.start();
  };
});
</script>
</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console