@@ -89,11 +89,44 @@ <h3>Model Configuration</h3>
89
89
let asrProcessor = null ;
90
90
91
91
function initializeUI ( ) {
92
+ console . log ( 'initializeUI called. Setting up ASR functionality...' ) ;
92
93
document . getElementById ( 'status' ) . textContent = 'WebAssembly module loaded. Ready to load models.' ;
93
94
setupASR ( ) ;
95
+ console . log ( 'setupASR called from initializeUI.' ) ;
94
96
}
95
97
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
+
96
128
function setupASR ( ) {
129
+ console . log ( 'setupASR function entered. Setting up event listeners...' ) ;
97
130
const loadBtn = document . getElementById ( 'load-asr-model' ) ;
98
131
const startBtn = document . getElementById ( 'start-asr' ) ;
99
132
const stopBtn = document . getElementById ( 'stop-asr' ) ;
@@ -102,10 +135,14 @@ <h3>Model Configuration</h3>
102
135
const modelTypeSelect = document . getElementById ( 'asr-model-type' ) ;
103
136
const controlsDiv = document . querySelector ( '.controls' ) ;
104
137
138
+ console . log ( 'DOM elements retrieved. Load button:' , loadBtn ) ;
139
+
105
140
let unloadBtn = null ;
106
141
107
142
// Update UI based on selected model type
143
+ console . log ( 'Setting up model type change listener...' ) ;
108
144
modelTypeSelect . addEventListener ( 'change' , ( ) => {
145
+ console . log ( 'Model type changed to:' , modelTypeSelect . value ) ;
109
146
const modelType = modelTypeSelect . value ;
110
147
const transducerElements = document . querySelectorAll ( '.transducer-model' ) ;
111
148
@@ -117,12 +154,20 @@ <h3>Model Configuration</h3>
117
154
}
118
155
} ) ;
119
156
} ) ;
157
+ console . log ( 'Model type change listener setup complete.' ) ;
120
158
159
+ console . log ( 'Setting up click event listener for Load ASR Model button...' ) ;
121
160
loadBtn . addEventListener ( 'click' , async ( ) => {
161
+ console . log ( 'Load ASR Model button clicked. Starting model loading process.' ) ;
122
162
loadBtn . disabled = true ;
123
163
loadBtn . textContent = 'Loading...' ;
124
164
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...' ) ;
126
171
try {
127
172
// Get options from UI
128
173
const modelType = modelTypeSelect . value ;
@@ -158,22 +203,33 @@ <h3>Model Configuration</h3>
158
203
// Load the model
159
204
const loadedModel = await SherpaOnnx . ASR . loadModel ( modelConfig ) ;
160
205
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
+
177
233
} catch ( error ) {
178
234
console . error ( 'Failed to load ASR model:' , error ) ;
179
235
loadBtn . textContent = 'Load Failed' ;
@@ -184,6 +240,24 @@ <h3>Model Configuration</h3>
184
240
185
241
startBtn . addEventListener ( 'click' , async ( ) => {
186
242
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
+
187
261
await getMicrophoneInput ( ) ;
188
262
189
263
// Create an online stream
0 commit comments