Upload 2 files
Browse files- punctuator.js +16 -3
- vad.js +15 -1
punctuator.js
CHANGED
|
@@ -36,13 +36,22 @@ const MULTILINGUAL_LABELS = {
|
|
| 36 |
const MULTILINGUAL_LANGS = ['de', 'fr', 'it', 'nl', 'es', 'pt'];
|
| 37 |
|
| 38 |
// Load the English punctuator model and vocab
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
async function loadEnglishPunctuator() {
|
| 40 |
if (pcsSession) return;
|
| 41 |
|
| 42 |
console.log('Loading English punctuator model...');
|
| 43 |
|
| 44 |
// Load vocab
|
| 45 |
-
const vocabResponse = await
|
| 46 |
const vocabData = await vocabResponse.json();
|
| 47 |
pcsVocab = vocabData.vocab;
|
| 48 |
|
|
@@ -53,7 +62,9 @@ async function loadEnglishPunctuator() {
|
|
| 53 |
}
|
| 54 |
|
| 55 |
// Load ONNX model
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
executionProviders: ['wasm'],
|
| 58 |
});
|
| 59 |
|
|
@@ -71,7 +82,9 @@ async function loadMultilingualPunctuator() {
|
|
| 71 |
multilingualTokenizer = await AutoTokenizer.from_pretrained('oliverguhr/fullstop-punctuation-multilingual-base');
|
| 72 |
|
| 73 |
// Load ONNX model
|
| 74 |
-
|
|
|
|
|
|
|
| 75 |
executionProviders: ['wasm'],
|
| 76 |
});
|
| 77 |
|
|
|
|
| 36 |
const MULTILINGUAL_LANGS = ['de', 'fr', 'it', 'nl', 'es', 'pt'];
|
| 37 |
|
| 38 |
// Load the English punctuator model and vocab
|
| 39 |
+
async function cachedFetch(url) {
|
| 40 |
+
const cache = await caches.open('granite-speech-local-models');
|
| 41 |
+
const cached = await cache.match(url);
|
| 42 |
+
if (cached) return cached;
|
| 43 |
+
const response = await fetch(url);
|
| 44 |
+
if (response.ok) await cache.put(url, response.clone());
|
| 45 |
+
return response;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
async function loadEnglishPunctuator() {
|
| 49 |
if (pcsSession) return;
|
| 50 |
|
| 51 |
console.log('Loading English punctuator model...');
|
| 52 |
|
| 53 |
// Load vocab
|
| 54 |
+
const vocabResponse = await cachedFetch('./pcs_vocab.json');
|
| 55 |
const vocabData = await vocabResponse.json();
|
| 56 |
pcsVocab = vocabData.vocab;
|
| 57 |
|
|
|
|
| 62 |
}
|
| 63 |
|
| 64 |
// Load ONNX model
|
| 65 |
+
const modelResponse = await cachedFetch('./punct_cap_seg_en.onnx');
|
| 66 |
+
const buffer = await modelResponse.arrayBuffer();
|
| 67 |
+
pcsSession = await ort.InferenceSession.create(buffer, {
|
| 68 |
executionProviders: ['wasm'],
|
| 69 |
});
|
| 70 |
|
|
|
|
| 82 |
multilingualTokenizer = await AutoTokenizer.from_pretrained('oliverguhr/fullstop-punctuation-multilingual-base');
|
| 83 |
|
| 84 |
// Load ONNX model
|
| 85 |
+
const modelResponse = await cachedFetch('./punct_multilingual_q8.onnx');
|
| 86 |
+
const buffer = await modelResponse.arrayBuffer();
|
| 87 |
+
multilingualSession = await ort.InferenceSession.create(buffer, {
|
| 88 |
executionProviders: ['wasm'],
|
| 89 |
});
|
| 90 |
|
vad.js
CHANGED
|
@@ -7,12 +7,26 @@ let vadSession = null;
|
|
| 7 |
const VAD_SAMPLE_RATE = 16000;
|
| 8 |
const VAD_CHUNK_SIZE = 512; // 32ms chunks at 16kHz
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
// Load VAD model
|
| 11 |
async function loadVAD() {
|
| 12 |
if (vadSession) return;
|
| 13 |
|
| 14 |
console.log('Loading VAD model...');
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
executionProviders: ['wasm'],
|
| 17 |
});
|
| 18 |
console.log('VAD model loaded');
|
|
|
|
| 7 |
const VAD_SAMPLE_RATE = 16000;
|
| 8 |
const VAD_CHUNK_SIZE = 512; // 32ms chunks at 16kHz
|
| 9 |
|
| 10 |
+
const MODEL_CACHE_NAME = 'granite-speech-local-models';
|
| 11 |
+
|
| 12 |
+
// Fetch with Cache API persistence
|
| 13 |
+
async function cachedFetch(url) {
|
| 14 |
+
const cache = await caches.open(MODEL_CACHE_NAME);
|
| 15 |
+
const cached = await cache.match(url);
|
| 16 |
+
if (cached) return cached;
|
| 17 |
+
const response = await fetch(url);
|
| 18 |
+
if (response.ok) await cache.put(url, response.clone());
|
| 19 |
+
return response;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
// Load VAD model
|
| 23 |
async function loadVAD() {
|
| 24 |
if (vadSession) return;
|
| 25 |
|
| 26 |
console.log('Loading VAD model...');
|
| 27 |
+
const response = await cachedFetch('./silero_vad.onnx');
|
| 28 |
+
const buffer = await response.arrayBuffer();
|
| 29 |
+
vadSession = await ort.InferenceSession.create(buffer, {
|
| 30 |
executionProviders: ['wasm'],
|
| 31 |
});
|
| 32 |
console.log('VAD model loaded');
|