From 187ca9b25ddbaa6fcd0fe7bee53547d6ad85917d Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Tue, 30 May 2023 14:47:43 -0400 Subject: [PATCH 1/2] chore: update email address --- js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/package.json b/js/package.json index ad63bcb..4d94920 100644 --- a/js/package.json +++ b/js/package.json @@ -32,7 +32,7 @@ "audio", "nlp" ], - "author": "David Huggins-Daines ", + "author": "David Huggins-Daines ", "license": "MIT", "bugs": { "url": "https://github.com/ReadAlongs/SoundSwallower/issues" From b1d2faf342f9a73e420564b6533356a7d9edf190 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Tue, 30 May 2023 15:26:52 -0400 Subject: [PATCH 2/2] fix: OMG, emscripten gratuitously breaks everything again --- js/CMakeLists.txt | 2 ++ js/api.js | 24 ++++++++++++------------ js/exported_functions.txt | 2 ++ js/library_funcs.txt | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/js/CMakeLists.txt b/js/CMakeLists.txt index 17b5ba7..558bc6c 100644 --- a/js/CMakeLists.txt +++ b/js/CMakeLists.txt @@ -47,6 +47,7 @@ target_link_options(soundswallower.jsonly PRIVATE @${CMAKE_SOURCE_DIR}/js/linker_options.txt --extern-pre-js ${CMAKE_SOURCE_DIR}/js/api-web-pre.js -sENVIRONMENT=web -sWASM=0 + -sUSE_PTHREADS=0 -sSTRICT=0 # Work around emscripten bug -sMODULARIZE=1 -sEXPORT_ES6=1 -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=@${CMAKE_SOURCE_DIR}/js/library_funcs.txt -sEXPORTED_FUNCTIONS=@${CMAKE_SOURCE_DIR}/js/exported_functions.txt) @@ -58,6 +59,7 @@ target_link_options(soundswallower.bundle PRIVATE --extern-pre-js ${CMAKE_SOURCE_DIR}/js/api-web-pre.js --extern-post-js ${CMAKE_SOURCE_DIR}/js/api-bundle-post.js -sENVIRONMENT=web -sWASM=0 + -sUSE_PTHREADS=0 -sSTRICT=0 # Work around emscripten bug -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=@${CMAKE_SOURCE_DIR}/js/library_funcs.txt -sEXPORTED_FUNCTIONS=@${CMAKE_SOURCE_DIR}/js/exported_functions.txt) # See diff --git a/js/api.js b/js/api.js index 1d20437..545e642 100644 --- a/js/api.js +++ b/js/api.js @@ -29,7 +29,7 @@ class Decoder { if (config === undefined) config = {}; if (Module.defaultModel !== null && config.hmm === undefined) config.hmm = Module.get_model_path(Module.defaultModel); - const cjson = allocateUTF8(JSON.stringify(config)); + const cjson = stringToNewUTF8(JSON.stringify(config)); const cconfig = Module._config_parse_json(0, cjson); Module._free(cjson); this.cdecoder = Module._decoder_create(cconfig); @@ -57,7 +57,7 @@ class Decoder { * @throws {ReferenceError} Throws ReferenceError if key is not a known parameter. */ set_config(key, val) { - const ckey = allocateUTF8(key); + const ckey = stringToNewUTF8(key); const cconfig = Module._decoder_config(this.cdecoder); const type = Module._config_typeof(cconfig, ckey); if (type == 0) { @@ -65,7 +65,7 @@ class Decoder { throw new ReferenceError(`Unknown configuration parameter ${key}`); } if (type & ARG_STRING) { - const cval = allocateUTF8(val); + const cval = stringToNewUTF8(val); Module._config_set_str(cconfig, ckey, cval); Module._free(cval); } else if (type & ARG_FLOATING) { @@ -85,7 +85,7 @@ class Decoder { * @throws {ReferenceError} Throws ReferenceError if key is not a known parameter. */ unset_config(key) { - const ckey = allocateUTF8(key); + const ckey = stringToNewUTF8(key); const cconfig = Module._decoder_config(this.cdecoder); const type = Module._config_typeof(cconfig, ckey); if (type == 0) { @@ -102,7 +102,7 @@ class Decoder { * @throws {ReferenceError} Throws ReferenceError if key is not a known parameter. */ get_config(key) { - const ckey = allocateUTF8(key); + const ckey = stringToNewUTF8(key); const cconfig = Module._decoder_config(this.cdecoder); const type = Module._config_typeof(cconfig, ckey); if (type == 0) { @@ -131,7 +131,7 @@ class Decoder { * @param {string} key Key whose existence to check. */ has_config(key) { - const ckey = allocateUTF8(key); + const ckey = stringToNewUTF8(key); const cconfig = Module._decoder_config(this.cdecoder); const rv = Module._config_typeof(cconfig, ckey) != 0; Module._free(ckey); @@ -415,7 +415,7 @@ class Decoder { */ lookup_word(word) { this.assert_initialized(); - const cword = allocateUTF8(word); + const cword = stringToNewUTF8(word); const cpron = Module._decoder_lookup_word(this.cdecoder, cword); Module._free(cword); if (cpron == 0) return null; @@ -441,8 +441,8 @@ class Decoder { throw new Error( `Word at position ${i} has missing text or pronunciation` ); - const ctext = allocateUTF8(text); - const cpron = allocateUTF8(pron); + const ctext = stringToNewUTF8(text); + const cpron = stringToNewUTF8(pron); const update = i == words.length - 1; const wid = Module._decoder_add_word(this.cdecoder, ctext, cpron, update); Module._free(ctext); @@ -463,13 +463,13 @@ class Decoder { const logmath = Module._decoder_logmath(this.cdecoder); const config = Module._decoder_config(this.cdecoder); const lw = this.get_config("lw"); - const cjsgf = allocateUTF8(jsgf_string); + const cjsgf = stringToNewUTF8(jsgf_string); const jsgf = Module._jsgf_parse_string(cjsgf, 0); Module._free(cjsgf); if (jsgf == 0) throw new Error("Failed to parse JSGF"); let rule; if (toprule !== null) { - const crule = allocateUTF8(toprule); + const crule = stringToNewUTF8(toprule); rule = Module._jsgf_get_rule(jsgf, crule); Module._free(crule); if (rule == 0) throw new Error("Failed to find top rule " + toprule); @@ -490,7 +490,7 @@ class Decoder { */ set_align_text(text) { this.assert_initialized(); - const ctext = allocateUTF8(text); + const ctext = stringToNewUTF8(text); const rv = Module._decoder_set_align_text(this.cdecoder, ctext); Module._free(ctext); if (rv < 0) throw new Error("Failed to set alignment text"); diff --git a/js/exported_functions.txt b/js/exported_functions.txt index 51aed54..4510b37 100644 --- a/js/exported_functions.txt +++ b/js/exported_functions.txt @@ -67,3 +67,5 @@ _endpointer_speech_start _endpointer_speech_end _endpointer_process _endpointer_end_stream +stringToNewUTF8 +ccall diff --git a/js/library_funcs.txt b/js/library_funcs.txt index 2410bdf..3332ab7 100644 --- a/js/library_funcs.txt +++ b/js/library_funcs.txt @@ -1,2 +1,2 @@ -$allocateUTF8 +$stringToNewUTF8 $ccall