-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.html
91 lines (81 loc) · 2.68 KB
/
index.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html lang="en">
<head>
<script src="node_modules/@picovoice/cobra-web/dist/iife/index.js"></script>
<script src="node_modules/@picovoice/web-voice-processor/dist/iife/index.js"></script>
<script type="application/javascript">
function writeMessage(message) {
console.log(message);
document.getElementById("status").innerHTML = message;
}
function writeVoiceProbability(message, value) {
document.getElementById("voiceProbabilityText").innerHTML = message;
document.getElementById("voiceProbabilityRange").value = value * 100;
}
function voiceProbabilityCallback(voiceProbability) {
const timestamp = new Date();
writeVoiceProbability(
`Voice detected with probability of ${voiceProbability.toFixed(2)} at ${timestamp.toString()}`,
voiceProbability
);
}
async function startCobra(accessKey) {
writeMessage("Cobra is loading. Please wait...");
let cobra = null;
try {
cobra = await CobraWeb.CobraWorker.create(
accessKey,
voiceProbabilityCallback
);
} catch (error) {
writeMessage(error);
throw new Error(error);
}
writeMessage("Cobra worker ready!");
writeMessage(
"WebVoiceProcessor initializing. Microphone permissions requested ..."
);
try {
WebVoiceProcessor.WebVoiceProcessor.subscribe(cobra);
writeMessage("WebVoiceProcessor ready and listening!");
} catch (e) {
writeMessage("WebVoiceProcessor failed to initialize: " + e);
}
}
</script>
</head>
<body>
<h1>Cobra Web Demo - worker</h1>
<p>
This demo uses Cobra for Web and the WebVoiceProcessor packages to create
an instance of Cobra that listens for voice activity and outputs them to
the page. After entering the AccessKey, click the "run Cobra" button.
</p>
<label for="accessKey"
>AccessKey string provided by
<a href="https://picovoice.ai/console/">Picovoice Console</a>:</label
>
<input type="text" id="accessKey" name="accessKey" />
<input
type="button"
id="submit"
value="Run Cobra"
onclick="startCobra(document.getElementById('accessKey').value)"
/>
<hr />
<div id="status" style="white-space: pre;"></div>
<div id="voiceProbability" class="voiceProbability">
<h2 id="voiceProbabilityText">
</h2>
<input
type="range"
min="0"
max="100"
value="0"
class="slider"
disabled="true"
id="voiceProbabilityRange"
/>
</div>
</body>
</html>