Skip to content

Commit ee6f9d1

Browse files
committed
wip: failure state
1 parent c4e3127 commit ee6f9d1

11 files changed

+683
-129
lines changed

wasm/combined/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ When built, the following files are generated:
1515
- `sherpa-onnx-wasm-combined.wasm` - The WebAssembly binary
1616
- `sherpa-onnx-wasm-combined.data` - The preloaded assets (models)
1717
- JS library files:
18-
- `sherpa-onnx-core.js` - Core functionality
19-
- `sherpa-onnx-asr.js` - ASR functionality
20-
- `sherpa-onnx-vad.js` - VAD functionality
21-
- `sherpa-onnx-tts.js` - TTS functionality
22-
- `sherpa-onnx-kws.js` - Keyword Spotting functionality
23-
- `sherpa-onnx-speaker.js` - Speaker Diarization functionality
24-
- `sherpa-onnx-enhancement.js` - Speech Enhancement functionality
18+
- `sherpa-onnx-combined-core.js` - Core functionality
19+
- `sherpa-onnx-combined-asr.js` - ASR functionality
20+
- `sherpa-onnx-combined-vad.js` - VAD functionality
21+
- `sherpa-onnx-combined-tts.js` - TTS functionality
22+
- `sherpa-onnx-combined-kws.js` - Keyword Spotting functionality
23+
- `sherpa-onnx-combined-speaker.js` - Speaker Diarization functionality
24+
- `sherpa-onnx-combined-enhancement.js` - Speech Enhancement functionality
2525
- `sherpa-onnx-combined.js` - Combined functionality wrapper
2626

2727
## Building

wasm/combined/demos/asr.html

+91-17
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,44 @@ <h3>Model Configuration</h3>
8989
let asrProcessor = null;
9090

9191
function initializeUI() {
92+
console.log('initializeUI called. Setting up ASR functionality...');
9293
document.getElementById('status').textContent = 'WebAssembly module loaded. Ready to load models.';
9394
setupASR();
95+
console.log('setupASR called from initializeUI.');
9496
}
9597

98+
// Define the callback that sherpa-onnx-combined.js will execute
99+
window.onSherpaOnnxReady = function(success, errorOrMissing) {
100+
console.log('onSherpaOnnxReady callback triggered. Success status:', success);
101+
if (success) {
102+
console.log("Sherpa-ONNX modules ready, initializing UI.");
103+
// Additional check for HEAPF32 availability before enabling UI
104+
if (window.Module && window.Module.HEAPF32) {
105+
console.log("HEAPF32 confirmed available. UI fully enabled.");
106+
document.getElementById('status').textContent = 'WebAssembly module and HEAPF32 ready. Ready to load models.';
107+
initializeUI();
108+
document.getElementById('load-asr-model').disabled = false;
109+
} else {
110+
console.error("HEAPF32 not available despite modules being ready. UI partially enabled with warning.");
111+
document.getElementById('status').textContent = 'Warning: WebAssembly module ready but HEAPF32 not available. Some functions may not work.';
112+
initializeUI();
113+
document.getElementById('load-asr-model').disabled = false; // Enable anyway for testing
114+
}
115+
} else {
116+
console.error("Failed to load Sherpa-ONNX modules:", errorOrMissing);
117+
document.getElementById('status').textContent = 'Error: Failed to load necessary modules. Check console.';
118+
// Disable controls if loading failed
119+
document.getElementById('load-asr-model').disabled = true;
120+
document.getElementById('start-asr').disabled = true;
121+
document.getElementById('stop-asr').disabled = true;
122+
}
123+
// Force enable the button for testing purposes
124+
console.log('Forcing enable of Load ASR Model button for debugging purposes.');
125+
document.getElementById('load-asr-model').disabled = false;
126+
};
127+
96128
function setupASR() {
129+
console.log('setupASR function entered. Setting up event listeners...');
97130
const loadBtn = document.getElementById('load-asr-model');
98131
const startBtn = document.getElementById('start-asr');
99132
const stopBtn = document.getElementById('stop-asr');
@@ -102,10 +135,14 @@ <h3>Model Configuration</h3>
102135
const modelTypeSelect = document.getElementById('asr-model-type');
103136
const controlsDiv = document.querySelector('.controls');
104137

138+
console.log('DOM elements retrieved. Load button:', loadBtn);
139+
105140
let unloadBtn = null;
106141

107142
// Update UI based on selected model type
143+
console.log('Setting up model type change listener...');
108144
modelTypeSelect.addEventListener('change', () => {
145+
console.log('Model type changed to:', modelTypeSelect.value);
109146
const modelType = modelTypeSelect.value;
110147
const transducerElements = document.querySelectorAll('.transducer-model');
111148

@@ -117,12 +154,20 @@ <h3>Model Configuration</h3>
117154
}
118155
});
119156
});
157+
console.log('Model type change listener setup complete.');
120158

159+
console.log('Setting up click event listener for Load ASR Model button...');
121160
loadBtn.addEventListener('click', async () => {
161+
console.log('Load ASR Model button clicked. Starting model loading process.');
122162
loadBtn.disabled = true;
123163
loadBtn.textContent = 'Loading...';
124164
statusElem.textContent = 'Status: Loading model...';
125-
165+
console.log('Current SherpaOnnx readiness status:', !!SherpaOnnx.isReady);
166+
console.log('window.Module status:', !!window.Module);
167+
if (window.Module) {
168+
console.log('window.Module.HEAPF32 status:', !!window.Module.HEAPF32);
169+
}
170+
console.log('Attempting to load model with current configuration...');
126171
try {
127172
// Get options from UI
128173
const modelType = modelTypeSelect.value;
@@ -158,22 +203,33 @@ <h3>Model Configuration</h3>
158203
// Load the model
159204
const loadedModel = await SherpaOnnx.ASR.loadModel(modelConfig);
160205

161-
// Create the ASR recognizer
162-
asr = SherpaOnnx.ASR.createOnlineRecognizer(loadedModel, {
163-
debug: debug
164-
});
165-
166-
loadBtn.textContent = 'Model Loaded';
167-
statusElem.textContent = 'Status: Model loaded successfully';
168-
startBtn.disabled = false;
169-
170-
// Add unload button if it doesn't exist
171-
if (!unloadBtn) {
172-
unloadBtn = createUnloadButton(controlsDiv, 'ASR', asr, statusElem);
173-
unloadBtn.id = 'unload-asr-model';
174-
} else {
175-
unloadBtn.disabled = false;
176-
}
206+
// Use setTimeout to delay recognizer creation slightly
207+
setTimeout(() => {
208+
try {
209+
// Create the ASR recognizer
210+
asr = SherpaOnnx.ASR.createOnlineRecognizer(loadedModel, {
211+
debug: debug
212+
});
213+
214+
loadBtn.textContent = 'Model Loaded';
215+
statusElem.textContent = 'Status: Model loaded successfully';
216+
startBtn.disabled = false;
217+
218+
// Add unload button if it doesn't exist
219+
if (!unloadBtn) {
220+
unloadBtn = createUnloadButton(controlsDiv, 'ASR', asr, statusElem);
221+
unloadBtn.id = 'unload-asr-model';
222+
} else {
223+
unloadBtn.disabled = false;
224+
}
225+
} catch (innerError) {
226+
console.error('Failed to create ASR recognizer (inside setTimeout):', innerError);
227+
loadBtn.textContent = 'Load Failed';
228+
statusElem.textContent = `Status: Error (delayed init) - ${innerError.message}`;
229+
loadBtn.disabled = false; // Re-enable load button on inner error
230+
}
231+
}, 0); // Delay of 0ms allows event loop tick
232+
177233
} catch (error) {
178234
console.error('Failed to load ASR model:', error);
179235
loadBtn.textContent = 'Load Failed';
@@ -184,6 +240,24 @@ <h3>Model Configuration</h3>
184240

185241
startBtn.addEventListener('click', async () => {
186242
try {
243+
// Check if WebAssembly module is fully initialized
244+
if (!window.Module) {
245+
statusElem.textContent = 'Status: Waiting for WebAssembly module to initialize...';
246+
await new Promise((resolve, reject) => {
247+
const checkInterval = setInterval(() => {
248+
if (window.Module) {
249+
clearInterval(checkInterval);
250+
resolve();
251+
}
252+
}, 100);
253+
setTimeout(() => {
254+
clearInterval(checkInterval);
255+
reject(new Error('WebAssembly module initialization timed out after 30 seconds'));
256+
}, 30000);
257+
});
258+
}
259+
statusElem.textContent = 'Status: WebAssembly module initialized. Starting audio processing...';
260+
187261
await getMicrophoneInput();
188262

189263
// Create an online stream

wasm/combined/demos/common.js

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
// common.js - Shared utilities for Sherpa-ONNX WASM demos
2+
3+
// --- Emscripten Module configuration ---
4+
// This MUST run before sherpa-onnx-wasm-combined.js is loaded
5+
var Module = Module || {};
6+
Module.locateFile = function(path, prefix) {
7+
// If the path is the wasm or data file, load it from the parent directory
8+
if (path.endsWith('.wasm') || path.endsWith('.data')) {
9+
// Assumes demos are in a subdirectory (like /demos/)
10+
// Adjust this path if your structure is different
11+
return `../${path}`;
12+
}
13+
// Otherwise, use the default logic (usually prefix + path)
14+
return prefix + path;
15+
};
16+
// --- End Emscripten Module configuration ---
17+
118
// Set up initialization callback
219
window.onSherpaOnnxReady = function(success, error) {
320
if (success) {

0 commit comments

Comments
 (0)