Wit.ai Microphone Demo

Tutorials of (Wit.ai microphone demo) by Ian jennings

<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>Wit.ai Microphone Demo</title>
  
  
  
  
  
</head>

<body>
  <link rel="stylesheet" href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/100379/microphone_2.css">  <script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/100379/microphone.js"></script>

<div id="microphone"></div>
<pre id="result"></pre>
<div id="info"></div>
  
    <script  src="js/index.js"></script>

</body>
</html>
/* Downloaded from https://www.codeseek.co/ */
/* Downloaded from https://www.codeseek.co/ */
 var mic = new Wit.Microphone(document.getElementById("microphone"));
    var info = function (msg) {
      document.getElementById("info").innerHTML = msg;
    };
    mic.onready = function () {
      info("Microphone is ready to record");
    };
    mic.onaudiostart = function () {
      info("Recording started");
    };
    mic.onaudioend = function () {
      info("Recording stopped, processing started");
    };
    mic.onerror = function (err) {
      info("Error: " + err);
    };
    mic.onresult = function (intent, entities) {
      var r = kv("intent", intent);

      for (var k in entities) {
        var e = entities[k];

        if (!(e instanceof Array)) {
          r += kv(k, e.value);
        } else {
          for (var i = 0; i < e.length; i++) {
            r += kv(k, e[i].value);
          }
        }
      }

      document.getElementById("result").innerHTML = r;
    };
    mic.connect("PYKE2SEOG5SO46P2XMUXQOJTA77MT6FH");
    // mic.start();
    // mic.stop();

    function kv (k, v) {
      if (toString.call(v) !== "[object String]") {
        v = JSON.stringify(v);
      }
      return k + "=" + v + "\n";
    }

This awesome code ( Wit.ai Microphone Demo ) is write by Ian Jennings, you can se more from this user in the personal repository

You can find the original code on Codepen.io

2018 © Ian Jennings