-
Notifications
You must be signed in to change notification settings - Fork 0
/
testmicrophonewit
69 lines (63 loc) · 1.84 KB
/
testmicrophonewit
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
<html>
<head>
<link rel="stylesheet" href="microphone/microphone.min.css">
</head>
<body style="text-align: center;">
<center><div id="microphone"></div></center>
<pre id="result"></pre>
<div id="info"></div>
<div id="error"></div>
<script src="microphone/microphone.min.js"></script>
<script>
var mic = new Wit.Microphone(document.getElementById("microphone"));
var info = function (msg) {
document.getElementById("info").innerHTML = msg;
};
var error = function (msg) {
document.getElementById("error").innerHTML = msg;
};
mic.onready = function () {
info("Microphone is ready to record");
};
mic.onaudiostart = function () {
info("Recording started");
error("");
};
mic.onaudioend = function () {
info("Recording stopped, processing started");
};
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.onerror = function (err) {
error("Error: " + err);
};
mic.onconnecting = function () {
info("Microphone is connecting");
};
mic.ondisconnected = function () {
info("Microphone is not connected");
};
mic.connect("CLIENT_TOKEN");
// mic.start();
// mic.stop();
function kv (k, v) {
if (toString.call(v) !== "[object String]") {
v = JSON.stringify(v);
}
return k + "=" + v + "\n";
}
</script>
</body>
</html>