@@ -71,6 +71,7 @@ let processBufferSize; //defines '_processRingBuffer' size together with 'inputS
7171
7272let keywords ;
7373let sensitivities ;
74+ let keywordsRemoteLocation ;
7475
7576let gateIsOpen = false ;
7677let _gateOpenTS = 0 ;
@@ -159,6 +160,7 @@ function constructWorker(options) {
159160
160161 keywords = options . setup . keywords || [ "Computer" ] ; //TODO: use 'options.setup.keywordsData'?
161162 sensitivities = options . setup . sensitivities || [ 0.5 ] ;
163+ keywordsRemoteLocation = options . setup . keywordsRemoteLocation ;
162164
163165 //load module
164166 if ( porcupineVersion <= 16 ) {
@@ -186,9 +188,27 @@ function constructWorker(options) {
186188 }
187189
188190 //load keywords (into 'PorcupineKeywords')
191+ var kwLoadErrors = false ;
189192 keywords . forEach ( function ( kw ) {
190- importScripts ( './picovoice/porcupine-keywords/' + kw . replace ( / \s + / , "_" ) . toLowerCase ( ) + "_wasm_" + porcupineVersionAndLang + '.js' ) ;
193+ kw = kw . toLowerCase ( ) . trim ( ) ;
194+ //support custom paths
195+ if ( kw . indexOf ( "server:" ) == 0 || kw . indexOf ( "remote:" ) == 0 ) {
196+ if ( keywordsRemoteLocation ) {
197+ kw = kw . toLowerCase ( ) . replace ( / ^ ( s e r v e r | r e m o t e ) : / , "" ) . trim ( ) ;
198+ var dotVersion = + porcupineVersion / 10 + "" ;
199+ if ( dotVersion . indexOf ( "." ) < 0 ) dotVersion = dotVersion + ".0" ; //Note to myself: supporting two different notations for version was a terrible idea!! (2.0 and 20 etc.)
200+ importScripts ( keywordsRemoteLocation . replace ( / \/ $ / , "" ) + "/" + porcupineVersionAndLang . replace ( / \d + / , dotVersion ) + "/keywords/" + kw . replace ( / \s + / , "_" ) + "_wasm_" + porcupineVersionAndLang + '.js' ) ;
201+ } else {
202+ kwLoadErrors = true ;
203+ }
204+ } else {
205+ importScripts ( './picovoice/porcupine-keywords/' + kw . replace ( / \s + / , "_" ) + "_wasm_" + porcupineVersionAndLang + '.js' ) ;
206+ }
191207 } ) ;
208+ if ( kwLoadErrors ) {
209+ sendError ( { name : "PorcupineModuleException" , message : "Failed to load one or more keywords (missing 'keywordsRemoteLocation' info?)" } ) ;
210+ return ;
211+ }
192212
193213 //build Porcupine
194214 PorcupineBuilder ( wasmFileArrayBuffer , defaultWasmBinaryFile , function ( buildResult ) {
0 commit comments