Pen Settings



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


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


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.


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.


                <!doctype html>
  <script src=""></script>
  <script src=""></script>
  <script src=""></script>
  <script src=""></script>
  <script src=""></script>
  <link rel="stylesheet" href="//" />
  <link rel="stylesheet" href="" />
<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>


  "set timer for 45 minutes"
  "set alarm for 5 o'clock"
  "what time is it"

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

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

<script type="text/ohm-js">
// An Ohm grammar for parsing voice commands
  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+
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) {
      publish_key: 'YOUR_PUB_KEY',
      subscribe_key: 'YOUR_SUB_KEY',
    $rootScope.initialized = true;

  var msgCallback = function(payload) {
    $scope.$apply(function() {

  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};

        channel: $scope.msgChannel,
        message: result