|
1 |
| -<!DOCTYPE html> |
| 1 | +<!doctype html> |
2 | 2 | <html lang="en">
|
3 |
| -<head> |
4 |
| - <script src="node_modules/@picovoice/web-voice-processor/dist/iife/index.js"></script> |
5 |
| - <script src="node_modules/@picovoice/porcupine-web/dist/iife/index.js"></script> |
6 |
| - <script src="keywords/porcupineKeywords.js"></script> |
7 |
| - <script src="models/porcupineModel.js"></script> |
8 |
| - <script type="application/javascript"> |
9 |
| - |
10 |
| - let porcupine = null; |
11 |
| - |
12 |
| - window.addEventListener('load', function () { |
13 |
| - let usingBuiltIns = false; |
14 |
| - if(porcupineKeywords.length === 0 && porcupineModel.publicPath.endsWith("porcupine_params.pv")) { |
15 |
| - usingBuiltIns = true; |
16 |
| - for(const k in PorcupineWeb.BuiltInKeyword) { |
17 |
| - porcupineKeywords.push(k); |
18 |
| - } |
19 |
| - } |
20 |
| - |
21 |
| - let select = document.getElementById("keywords"); |
22 |
| - for(let i = 0; i < porcupineKeywords.length; i++) { |
23 |
| - let el = document.createElement("option"); |
24 |
| - el.textContent = usingBuiltIns ? PorcupineWeb.BuiltInKeyword[porcupineKeywords[i]] : porcupineKeywords[i].label; |
25 |
| - el.value = `${i}`; |
26 |
| - select.appendChild(el); |
27 |
| - } |
28 |
| - }); |
29 |
| - |
30 |
| - function writeMessage(message) { |
31 |
| - console.log(message); |
32 |
| - document.getElementById("status").innerHTML = message; |
33 |
| - } |
34 |
| - |
35 |
| - function porcupineErrorCallback(error) { |
36 |
| - writeMessage(error); |
37 |
| - } |
38 |
| - |
39 |
| - function porcupineKeywordCallback(detection) { |
40 |
| - const time = new Date(); |
41 |
| - const message = `keyword detected at ${time.toLocaleTimeString()}: ${detection.label} (index = ${detection.index})` |
42 |
| - console.log(message); |
43 |
| - document.getElementById("result").innerHTML = message; |
44 |
| - } |
45 |
| - |
46 |
| - async function startPorcupine(accessKey, keywordIndex) { |
47 |
| - if (window.WebVoiceProcessor.WebVoiceProcessor.isRecording) { |
48 |
| - await window.WebVoiceProcessor.WebVoiceProcessor.unsubscribe(porcupine); |
49 |
| - await porcupine.terminate(); |
50 |
| - } |
51 |
| - |
52 |
| - writeMessage("Porcupine is loading. Please wait..."); |
53 |
| - try { |
54 |
| - porcupine = await PorcupineWeb.PorcupineWorker.create( |
55 |
| - accessKey, |
56 |
| - [porcupineKeywords[keywordIndex]], |
57 |
| - porcupineKeywordCallback, |
58 |
| - porcupineModel |
59 |
| - ); |
60 |
| - |
61 |
| - writeMessage("Porcupine worker ready!"); |
62 |
| - |
63 |
| - writeMessage( |
64 |
| - "WebVoiceProcessor initializing. Microphone permissions requested ..." |
65 |
| - ); |
66 |
| - await window.WebVoiceProcessor.WebVoiceProcessor.subscribe(porcupine); |
67 |
| - |
68 |
| - writeMessage("WebVoiceProcessor ready and listening!"); |
69 |
| - } catch (err) { |
70 |
| - porcupineErrorCallback(err); |
71 |
| - } |
72 |
| - } |
73 |
| - </script> |
74 |
| -</head> |
75 |
| -<body> |
76 |
| -<h1>Porcupine Web Demo</h1> |
77 |
| -<p>This demo uses Porcupine for Web and the WebVoiceProcessor to:</p> |
78 |
| -<ol> |
79 |
| - <li> |
80 |
| - Create an instance of Porcupine that listens for the selected keyword. |
81 |
| - </li> |
82 |
| - <li> |
83 |
| - Acquire microphone (& ask permission) data stream and convert to voice |
84 |
| - processing format (16kHz 16-bit linear PCM). The down-sampled audio is |
85 |
| - forwarded to the Porcupine engine. The audio <i>does not</i> leave the |
86 |
| - browser: all processing is occurring via the Porcupine WebAssembly code. |
87 |
| - </li> |
88 |
| - <li> |
89 |
| - Listen for keyword detection events from the Porcupine engines and output them to the page. |
90 |
| - </li> |
91 |
| -</ol> |
92 |
| -<p>After entering the AccessKey, click the "Start Porcupine" button.</p> |
93 |
| -<p>While listening you can try out different keywords using the "Keywords" dropdown.</p> |
94 |
| -<hr/> |
95 |
| -<label for="accessKey" |
96 |
| ->AccessKey obtained from |
97 |
| - <a href="https://console.picovoice.ai/">Picovoice Console</a>:</label |
98 |
| -> |
99 |
| -<input type="text" id="accessKey" name="accessKey"/> |
100 |
| -<input |
101 |
| - type="button" |
102 |
| - id="submit" |
103 |
| - value="Start Porcupine" |
104 |
| - onclick="startPorcupine( |
| 3 | + <head> |
| 4 | + <script src="node_modules/@picovoice/web-voice-processor/dist/iife/index.js"></script> |
| 5 | + <script src="node_modules/@picovoice/porcupine-web/dist/iife/index.js"></script> |
| 6 | + <script src="keywords/porcupineKeywords.js"></script> |
| 7 | + <script src="models/porcupineModel.js"></script> |
| 8 | + <script type="application/javascript" src="scripts/porcupine.js"></script> |
| 9 | + </head> |
| 10 | + <body> |
| 11 | + <h1>Porcupine Web Demo</h1> |
| 12 | + <p>This demo uses Porcupine for Web and the WebVoiceProcessor to:</p> |
| 13 | + <ol> |
| 14 | + <li> |
| 15 | + Create an instance of Porcupine that listens for the selected keyword. |
| 16 | + </li> |
| 17 | + <li> |
| 18 | + Acquire microphone (& ask permission) data stream and convert to voice |
| 19 | + processing format (16kHz 16-bit linear PCM). The down-sampled audio is |
| 20 | + forwarded to the Porcupine engine. The audio <i>does not</i> leave the |
| 21 | + browser: all processing is occurring via the Porcupine WebAssembly code. |
| 22 | + </li> |
| 23 | + <li> |
| 24 | + Listen for keyword detection events from the Porcupine engines and |
| 25 | + output them to the page. |
| 26 | + </li> |
| 27 | + </ol> |
| 28 | + <p>After entering the AccessKey, click the "Start Porcupine" button.</p> |
| 29 | + <p> |
| 30 | + While listening you can try out different keywords using the "Keywords" |
| 31 | + dropdown. |
| 32 | + </p> |
| 33 | + <hr /> |
| 34 | + <label for="accessKey" |
| 35 | + >AccessKey obtained from |
| 36 | + <a href="https://console.picovoice.ai/">Picovoice Console</a>:</label |
| 37 | + > |
| 38 | + <input type="text" id="accessKey" name="accessKey" /> |
| 39 | + <input |
| 40 | + type="button" |
| 41 | + id="submit" |
| 42 | + value="Start Porcupine" |
| 43 | + onclick="startPorcupine( |
105 | 44 | document.getElementById('accessKey').value,
|
106 | 45 | parseInt(document.getElementById('keywords').value))"
|
107 |
| -/> |
108 |
| -<br> |
109 |
| -<br> |
110 |
| -<label for="keywords">Keyword:</label> |
111 |
| -<select |
112 |
| - id="keywords" |
113 |
| - name="keywords" |
114 |
| - onchange="if (window.WebVoiceProcessor.WebVoiceProcessor.isRecording) { startPorcupine( |
| 46 | + /> |
| 47 | + <br /> |
| 48 | + <br /> |
| 49 | + <label for="keywords">Keyword:</label> |
| 50 | + <select |
| 51 | + id="keywords" |
| 52 | + name="keywords" |
| 53 | + onchange="if (window.WebVoiceProcessor.WebVoiceProcessor.isRecording) { startPorcupine( |
115 | 54 | document.getElementById('accessKey').value,
|
116 |
| - parseInt(document.getElementById('keywords').value)) }"></select> |
117 |
| -<hr/> |
118 |
| -<div id="status" style="white-space: pre;"></div> |
119 |
| -<br> |
120 |
| -<div id="result"></div> |
121 |
| -</body> |
| 55 | + parseInt(document.getElementById('keywords').value)) }" |
| 56 | + ></select> |
| 57 | + <hr /> |
| 58 | + <div id="status" style="white-space: pre"></div> |
| 59 | + <br /> |
| 60 | + <div id="result"></div> |
| 61 | + </body> |
122 | 62 | </html>
|
0 commit comments