Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions js/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -57,15 +57,15 @@ 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) {
Module._free(ckey);
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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions js/exported_functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ _endpointer_speech_start
_endpointer_speech_end
_endpointer_process
_endpointer_end_stream
stringToNewUTF8
ccall
2 changes: 1 addition & 1 deletion js/library_funcs.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$allocateUTF8
$stringToNewUTF8
$ccall
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"audio",
"nlp"
],
"author": "David Huggins-Daines <dhdaines@gmail.com>",
"author": "David Huggins-Daines <dhd@ecolingui.ca>",
"license": "MIT",
"bugs": {
"url": "https://github.com/ReadAlongs/SoundSwallower/issues"
Expand Down