Build Kaldi with openblas instead of clapack-wasm. Size increased ti 616KB, but performance increased by 20% (thanks OpenBLAS!)
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,7 +2,7 @@ vosk
|
||||
kaldi
|
||||
.vscode
|
||||
index.html
|
||||
clapack-wasm
|
||||
OpenBLAS
|
||||
openfst
|
||||
emsdk
|
||||
test.js
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
# Overview
|
||||
- A lightweight, up to date speech recognizer in the browser with total brotlied (used by JSDelivr) size of **under a megabyte** (609 KB)
|
||||
- A lightweight, up to date speech recognizer in the browser with total brotlied (used by JSDelivr) size of **under a megabyte** (616 KB)
|
||||
- Live Demo (ASR in 20 languages): https://msqr1-github-io.pages.dev/Vosklet
|
||||
- Inspired by [vosk-browser](https://github.com/ccoreilly/vosk-browser)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
- Include model cache path management
|
||||
- Include model cache ID management (for updates)
|
||||
- Wraps all Vosk's functionaly
|
||||
- Faster than vosk-browser
|
||||
|
||||
# Basic usage (microphone recognition in English)
|
||||
- Using JsDelivr CDN
|
||||
|
||||
File diff suppressed because one or more lines are too long
BIN
Vosklet.wasm
BIN
Vosklet.wasm
Binary file not shown.
@@ -1,77 +0,0 @@
|
||||
diff --git a/CBLAS/Makefile.in.WASM b/CBLAS/Makefile.in.WASM
|
||||
index bf7eda6..5fedaf6 100644
|
||||
--- a/CBLAS/Makefile.in.WASM
|
||||
+++ b/CBLAS/Makefile.in.WASM
|
||||
@@ -36,7 +36,7 @@ LOADER = $(CC)
|
||||
# Flags for Compilers
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
-CFLAGS = -DADD_ -O3
|
||||
+CFLAGS = -DADD_ -O3 -flto -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Archive programs and flags
|
||||
diff --git a/CLAPACK-3.2.1/make.inc.WASM b/CLAPACK-3.2.1/make.inc.WASM
|
||||
index 80037d0..a964b2d 100644
|
||||
--- a/CLAPACK-3.2.1/make.inc.WASM
|
||||
+++ b/CLAPACK-3.2.1/make.inc.WASM
|
||||
@@ -23,7 +23,7 @@ PLAT =
|
||||
# This is used to compile C libary
|
||||
# if no wrapping of the blas library is needed, uncomment next line
|
||||
CC = emcc # -DNO_BLAS_WRAP
|
||||
-CFLAGS = -I$(TOPDIR)/INCLUDE -I$(TOPDIR)/../libf2c -O3
|
||||
+CFLAGS = -I$(TOPDIR)/INCLUDE -I$(TOPDIR)/../libf2c -O3 -fno-rtti -fno-exceptions -flto -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals
|
||||
LOADER = $(CC)
|
||||
LOADOPTS =
|
||||
NOOPT = -O0 -I$(TOPDIR)/INCLUDE -I$(TOPDIR)/../libf2c
|
||||
diff --git a/f2c_BLAS-3.8.0/make.inc.WASM b/f2c_BLAS-3.8.0/make.inc.WASM
|
||||
index e071614..4647c2b 100644
|
||||
--- a/f2c_BLAS-3.8.0/make.inc.WASM
|
||||
+++ b/f2c_BLAS-3.8.0/make.inc.WASM
|
||||
@@ -16,7 +16,7 @@ PLAT =
|
||||
# desired load options for your machine.
|
||||
#
|
||||
CC = emcc
|
||||
-CFLAGS = -I../libf2c -O3
|
||||
+CFLAGS = -I../libf2c -O3 -fno-rtti -fno-exceptions -flto -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals
|
||||
DRVOPTS = $(OPTS)
|
||||
NOOPT =
|
||||
LOADER = emcc
|
||||
diff --git a/libf2c/makefile.WASM b/libf2c/makefile.WASM
|
||||
index 6221401..d93b87f 100644
|
||||
--- a/libf2c/makefile.WASM
|
||||
+++ b/libf2c/makefile.WASM
|
||||
@@ -15,7 +15,7 @@
|
||||
.SUFFIXES: .c .o
|
||||
CC = emcc
|
||||
SHELL = /bin/sh
|
||||
-CFLAGS = -DNON_UNIX_STDIO -O3
|
||||
+CFLAGS = -DNON_UNIX_STDIO -O3 -fno-rtti -fno-exceptions -flto -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals
|
||||
|
||||
LD = wasm-ld
|
||||
RANLIB = emranlib
|
||||
@@ -24,7 +24,7 @@ AR = emar
|
||||
# compile, then strip unnecessary symbols
|
||||
.c.o:
|
||||
$(CC) -c -DSkip_f2c_Undefs $(CFLAGS) $*.c
|
||||
- $(LD) --relocatable -o $*.xxx $*.o
|
||||
+ $(LD) --no-entry -r -o $*.xxx $*.o
|
||||
mv $*.xxx $*.o
|
||||
## Under Solaris (and other systems that do not understand ld -x),
|
||||
## omit -x in the ld line above.
|
||||
diff --git a/libf2c/main.c b/libf2c/main.c
|
||||
index d95fdc9..ac82f68 100644
|
||||
--- a/libf2c/main.c
|
||||
+++ b/libf2c/main.c
|
||||
@@ -105,9 +105,9 @@ char **xargv;
|
||||
|
||||
int
|
||||
#ifdef KR_headers
|
||||
-main(argc, argv) int argc; char **argv;
|
||||
+m(argc, argv) int argc; char **argv;
|
||||
#else
|
||||
-main(int argc, char **argv)
|
||||
+m(int argc, char **argv)
|
||||
#endif
|
||||
{
|
||||
xargc = argc;
|
||||
@@ -1,33 +1,25 @@
|
||||
diff --git a/src/matrix/Makefile b/src/matrix/Makefile
|
||||
index 398179a35..c903fbfd4 100644
|
||||
--- a/src/matrix/Makefile
|
||||
+++ b/src/matrix/Makefile
|
||||
@@ -10,7 +10,6 @@ include ../kaldi.mk
|
||||
|
||||
# you can uncomment matrix-lib-speed-test if you want to do the speed tests.
|
||||
|
||||
-TESTFILES = matrix-lib-test sparse-matrix-test numpy-array-test #matrix-lib-speed-test
|
||||
|
||||
OBJFILES = kaldi-matrix.o kaldi-vector.o packed-matrix.o sp-matrix.o tp-matrix.o \
|
||||
matrix-functions.o qr.o srfft.o compressed-matrix.o \
|
||||
|
||||
|
||||
diff --git a/src/util/kaldi-thread.cc b/src/util/kaldi-thread.cc
|
||||
index 4573e24f1..4af4e73ea 100644
|
||||
--- a/src/util/kaldi-thread.cc
|
||||
+++ b/src/util/kaldi-thread.cc
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "util/kaldi-thread.h"
|
||||
|
||||
namespace kaldi {
|
||||
-int32 g_num_threads = 4; // Initialize this global variable.
|
||||
+int32 g_num_threads = 1; // Initialize this global variable.
|
||||
|
||||
MultiThreadable::~MultiThreadable() {
|
||||
// default implementation does nothing
|
||||
|
||||
diff --git a/src/configure b/src/configure
|
||||
index fc3aee6..c93e4e8 100755
|
||||
--- a/src/configure
|
||||
+++ b/src/configure
|
||||
@@ -1261,14 +1261,7 @@ or try another math library, e.g. --mathlib=OPENBLAS (Kaldi may be slower)."
|
||||
** You can also use other matrix algebra libraries. For information, see:
|
||||
** http://kaldi-asr.org/doc/matrixwrap.html"
|
||||
fi
|
||||
- if [ -f $OPENBLASROOT/lib/libopenblas.so ]; then
|
||||
- OPENBLASLIBDIR=$OPENBLASROOT/lib
|
||||
- elif [ -f $OPENBLASROOT/lib64/libopenblas.so ]; then
|
||||
- # in REDHAT/CentOS package installs, the library is located here
|
||||
- OPENBLASLIBDIR=$OPENBLASROOT/lib64
|
||||
- else
|
||||
- failure "Expected to find the file $OPENBLASROOT/lib/libopenblas.so"
|
||||
- fi
|
||||
+ OPENBLASLIBDIR=$OPENBLASROOT/lib
|
||||
if [ -f $OPENBLASROOT/include/cblas.h ] ; then
|
||||
OPENBLASINCDIR=$OPENBLASROOT/include
|
||||
elif [ -f $OPENBLASROOT/include/openblas/cblas.h ] ; then
|
||||
diff --git a/src/ivector/ivector-extractor.cc b/src/ivector/ivector-extractor.cc
|
||||
index c3a122281..71d37256d 100644
|
||||
index c3a1222..71d3725 100644
|
||||
--- a/src/ivector/ivector-extractor.cc
|
||||
+++ b/src/ivector/ivector-extractor.cc
|
||||
@@ -195,7 +195,7 @@ void IvectorExtractor::ComputeDerivedVars() {
|
||||
@@ -39,4 +31,28 @@ index c3a122281..71d37256d 100644
|
||||
TaskSequencer<IvectorExtractorComputeDerivedVarsClass> sequencer(
|
||||
sequencer_opts);
|
||||
for (int32 i = 0; i < NumGauss(); i++)
|
||||
|
||||
diff --git a/src/matrix/Makefile b/src/matrix/Makefile
|
||||
index 398179a..c903fbf 100644
|
||||
--- a/src/matrix/Makefile
|
||||
+++ b/src/matrix/Makefile
|
||||
@@ -10,7 +10,6 @@ include ../kaldi.mk
|
||||
|
||||
# you can uncomment matrix-lib-speed-test if you want to do the speed tests.
|
||||
|
||||
-TESTFILES = matrix-lib-test sparse-matrix-test numpy-array-test #matrix-lib-speed-test
|
||||
|
||||
OBJFILES = kaldi-matrix.o kaldi-vector.o packed-matrix.o sp-matrix.o tp-matrix.o \
|
||||
matrix-functions.o qr.o srfft.o compressed-matrix.o \
|
||||
diff --git a/src/util/kaldi-thread.cc b/src/util/kaldi-thread.cc
|
||||
index 4573e24..4af4e73 100644
|
||||
--- a/src/util/kaldi-thread.cc
|
||||
+++ b/src/util/kaldi-thread.cc
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "util/kaldi-thread.h"
|
||||
|
||||
namespace kaldi {
|
||||
-int32 g_num_threads = 4; // Initialize this global variable.
|
||||
+int32 g_num_threads = 1; // Initialize this global variable.
|
||||
|
||||
MultiThreadable::~MultiThreadable() {
|
||||
// default implementation does nothing
|
||||
|
||||
48
src/OpenBLAS.patch
Normal file
48
src/OpenBLAS.patch
Normal file
@@ -0,0 +1,48 @@
|
||||
diff --git a/Makefile.prebuild b/Makefile.prebuild
|
||||
index b7d695a..4069032 100644
|
||||
--- a/Makefile.prebuild
|
||||
+++ b/Makefile.prebuild
|
||||
@@ -72,7 +72,7 @@ TARGET_FLAGS = -march=rv64imafdcv -mabi=lp64d
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET), RISCV64_GENERIC)
|
||||
-TARGET_FLAGS = -march=rv64imafdc -mabi=lp64d
|
||||
+#TARGET_FLAGS = -march=rv64imafdc -mabi=lp64d
|
||||
endif
|
||||
|
||||
all: getarch_2nd
|
||||
diff --git a/Makefile.riscv64 b/Makefile.riscv64
|
||||
index 9f6e48b..a6b1a3f 100644
|
||||
--- a/Makefile.riscv64
|
||||
+++ b/Makefile.riscv64
|
||||
@@ -15,6 +15,6 @@ CCOMMON_OPT += -march=rv64imafdcv -mabi=lp64d
|
||||
FCOMMON_OPT += -march=rv64imafdcv -mabi=lp64d
|
||||
endif
|
||||
ifeq ($(CORE), RISCV64_GENERIC)
|
||||
-CCOMMON_OPT += -march=rv64imafdc -mabi=lp64d
|
||||
-FCOMMON_OPT += -march=rv64imafdc -mabi=lp64d
|
||||
+#CCOMMON_OPT += -march=rv64imafdc -mabi=lp64d
|
||||
+#FCOMMON_OPT += -march=rv64imafdc -mabi=lp64d
|
||||
endif
|
||||
diff --git a/Makefile.system b/Makefile.system
|
||||
index b065f9a..60dbd2d 100644
|
||||
--- a/Makefile.system
|
||||
+++ b/Makefile.system
|
||||
@@ -202,7 +202,7 @@ endif
|
||||
# On x86_64 build getarch with march=native unless the compiler is PGI. This is required to detect AVX512 support in getarch.
|
||||
ifeq ($(HOSTARCH), x86_64)
|
||||
ifeq ($(findstring pgcc,$(HOSTCC))$(findstring nvc,$(HOSTCC)),)
|
||||
-GETARCH_FLAGS += -march=native
|
||||
+#GETARCH_FLAGS += -march=native
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -1683,7 +1683,7 @@ FCOMMON_OPT += -g
|
||||
endif
|
||||
|
||||
ifndef COMMON_OPT
|
||||
-COMMON_OPT = -O2
|
||||
+COMMON_OPT = -O3
|
||||
endif
|
||||
|
||||
ifndef FCOMMON_OPT
|
||||
27
src/make
27
src/make
@@ -35,31 +35,36 @@ SRC=$(realpath src)
|
||||
KALDI=$(realpath kaldi)
|
||||
VOSK=$(realpath vosk)
|
||||
OPENFST=$(realpath openfst)
|
||||
CLAPACK_WASM=$(realpath clapack-wasm)
|
||||
OPENBLAS=$(realpath openblas)
|
||||
|
||||
if [ ! -d "$OPENFST" ]; then
|
||||
rm -rf /tmp/openfst &&
|
||||
git clone --depth=1 https://github.com/alphacep/openfst /tmp/openfst &&
|
||||
cd /tmp/openfst &&
|
||||
autoreconf -is &&
|
||||
CXXFLAGS="-r -O3 -fno-rtti -flto -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals -flto" emconfigure ./configure --prefix="$OPENFST" --enable-static --disable-shared --enable-lookahead-fsts --enable-ngram-fsts --disable-bin &&
|
||||
CXXFLAGS="-r -O3 -fno-rtti -flto -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals" emconfigure ./configure --prefix="$OPENFST" --enable-static --disable-shared --enable-lookahead-fsts --enable-ngram-fsts --disable-bin &&
|
||||
emmake make -j"$JOBS" install &&
|
||||
echo "PACKAGE_VERSION = 1.8.0" >> "$OPENFST"/Makefile
|
||||
rm -rf /tmp/openfst
|
||||
fi
|
||||
|
||||
if [ ! -d "$CLAPACK_WASM" ]; then
|
||||
git clone --depth=1 https://gitlab.inria.fr/multispeech/kaldi.web/clapack-wasm.git "$CLAPACK_WASM" &&
|
||||
cd "$CLAPACK_WASM" &&
|
||||
git apply "$SRC"/Clapack-wasm.patch &&
|
||||
bash install_repo.sh emcc
|
||||
if [ ! -d "$OPENBLAS" ]; then
|
||||
rm -rf /tmp/openblas &&
|
||||
git clone -b v0.3.28 https://github.com/OpenMathLib/OpenBLAS --depth=1 /tmp/openblas &&
|
||||
cd /tmp/openblas &&
|
||||
git apply "$SRC"/OpenBLAS.patch &&
|
||||
# Change HOSTCC to the default C compiler on your machine
|
||||
COMMON_FLAGS="CC=emcc HOSTCC=clang-20 TARGET=RISCV64_GENERIC USE_THREAD=0 NO_SHARED=1 BINARY=32 BUILD_SINGLE=1 BUILD_DOUBLE=1 BUILD_BFLOAT16=0 BUILD_COMPLEX16=0 BUILD_COMPLEX=0"
|
||||
CFLAGS="-fno-exceptions -fno-rtti -flto -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals -Wno-implicit-function-declaration -Wno-unused-function"
|
||||
make $COMMON_FLAGS CFLAGS="$CFLAGS" PREFIX="$OPENBLAS" -j"$JOBS" &&
|
||||
make $COMMON_FLAGS CFLAGS="$CFLAGS" PREFIX="$OPENBLAS" -j"$JOBS" install &&
|
||||
rm -rf /tmp/openblas
|
||||
fi
|
||||
|
||||
if [ ! -d "$KALDI" ]; then
|
||||
git clone -b vosk --depth=1 https://github.com/alphacep/kaldi "$KALDI" &&
|
||||
cd "$KALDI"/src &&
|
||||
git apply "$SRC"/Kaldi.patch &&
|
||||
CXXFLAGS="-O3 -UHAVE_EXECINFO_H -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -fwasm-exceptions -flto -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals -Wno-unused-variable -Wno-unused-but-set-variable -g0" LDFLAGS="-lembind" emconfigure ./configure --use-cuda=no --with-cudadecoder=no --static --static-math=yes --static-fst=yes --debug-level=0 --fst-root="$OPENFST" --clapack-root="$CLAPACK_WASM" --host=WASM &&
|
||||
CXXFLAGS="-O3 -UHAVE_EXECINFO_H -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -fwasm-exceptions -flto -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals -Wno-unused-variable -Wno-unused-but-set-variable -g0" LDFLAGS="-lembind" emconfigure ./configure --use-cuda=no --with-cudadecoder=no --static --static-math=yes --static-fst=yes --debug-level=0 --fst-root="$OPENFST" --openblas-root="$OPENBLAS" --host=WASM &&
|
||||
emmake make -j"$JOBS" online2 rnnlm
|
||||
fi
|
||||
|
||||
@@ -69,14 +74,14 @@ if [ ! -d "$VOSK" ]; then
|
||||
git apply "$SRC"/Vosk.patch &&
|
||||
VOSK_FILES="recognizer.o language_model.o model.o spk_model.o vosk_api.o" &&
|
||||
em++ -O3 -fwasm-exceptions -flto -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals -Wno-deprecated -I. -I"$KALDI"/src -I"$OPENFST"/include ${VOSK_FILES//.o/.cc} -c &&
|
||||
emar -rcs vosk.a $VOSK_FILES
|
||||
emar -rcs vosk.a $VOSK_FILES &&
|
||||
rm -f $VOSK_FILES
|
||||
fi
|
||||
|
||||
cd "$SRC" &&
|
||||
FILES="Util.o CommonModel.o Recognizer.o Bindings.o"
|
||||
COMMON_FLAGS="-O3 -flto -fno-rtti -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals"
|
||||
COMMON_LD_FLAGS="-sWASMFS -sWASM_BIGINT -sMODULARIZE -sTEXTDECODER=2 -sWASM_WORKERS=2 -sEVAL_CTORS=2 -sINITIAL_MEMORY="$INITIAL_MEMORY" -sALLOW_MEMORY_GROWTH -sPOLYFILL=0 -sEXIT_RUNTIME=0 -sINVOKE_RUN=0 -sSUPPORT_LONGJMP=0 -sINCOMING_MODULE_JS_API=wasmMemory,instantiateWasm,wasm -sEXPORT_NAME=loadVosklet -sMALLOC=emmalloc -sENVIRONMENT=web,worker -L"$KALDI"/src -l:online2/kaldi-online2.a -l:decoder/kaldi-decoder.a -l:ivector/kaldi-ivector.a -l:gmm/kaldi-gmm.a -l:tree/kaldi-tree.a -l:feat/kaldi-feat.a -l:cudamatrix/kaldi-cudamatrix.a -l:lat/kaldi-lat.a -l:lm/kaldi-lm.a -l:rnnlm/kaldi-rnnlm.a -l:hmm/kaldi-hmm.a -l:nnet3/kaldi-nnet3.a -l:transform/kaldi-transform.a -l:matrix/kaldi-matrix.a -l:fstext/kaldi-fstext.a -l:util/kaldi-util.a -l:base/kaldi-base.a -L"$OPENFST"/lib -l:libfst.a -l:libfstngram.a -L"$CLAPACK_WASM" -l:CBLAS/lib/cblas.a -l:CLAPACK-3.2.1/lapack.a -l:CLAPACK-3.2.1/libcblaswr.a -l:f2c_BLAS-3.8.0/blas.a -l:libf2c/libf2c.a -L"$VOSK"/src -l:vosk.a -lembind --closure 1 --pre-js"
|
||||
COMMON_LD_FLAGS="-sWASMFS -sWASM_BIGINT -sMODULARIZE -sTEXTDECODER=2 -sWASM_WORKERS=2 -sEVAL_CTORS=2 -sINITIAL_MEMORY=$INITIAL_MEMORY -sALLOW_MEMORY_GROWTH -sPOLYFILL=0 -sEXIT_RUNTIME=0 -sINVOKE_RUN=0 -sSUPPORT_LONGJMP=0 -sINCOMING_MODULE_JS_API=wasmMemory,instantiateWasm,wasm -sEXPORT_NAME=loadVosklet -sMALLOC=emmalloc -sENVIRONMENT=web,worker -L$KALDI/src -l:online2/kaldi-online2.a -l:decoder/kaldi-decoder.a -l:ivector/kaldi-ivector.a -l:gmm/kaldi-gmm.a -l:tree/kaldi-tree.a -l:feat/kaldi-feat.a -l:cudamatrix/kaldi-cudamatrix.a -l:lat/kaldi-lat.a -l:lm/kaldi-lm.a -l:rnnlm/kaldi-rnnlm.a -l:hmm/kaldi-hmm.a -l:nnet3/kaldi-nnet3.a -l:transform/kaldi-transform.a -l:matrix/kaldi-matrix.a -l:fstext/kaldi-fstext.a -l:util/kaldi-util.a -l:base/kaldi-base.a -L$OPENFST/lib -l:libfst.a -l:libfstngram.a -L$OPENBLAS -l:lib/libopenblas.a -L$VOSK/src -l:vosk.a -lembind --closure 1 --pre-js"
|
||||
em++ ${FILES//.o/.cc} $COMMON_FLAGS -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DMAX_WORKERS="$MAX_THREADS" -fno-exceptions -std=c++23 -c -I. -I"$VOSK"/src &&
|
||||
|
||||
em++ $FILES $COMMON_FLAGS $COMMON_LD_FLAGS Wrapper.js -o ../Vosklet.js
|
||||
|
||||
6
test
6
test
@@ -33,15 +33,15 @@ export PATH=:$PATH:$(realpath "$EMSDK")/upstream/bin
|
||||
KALDI=$(realpath kaldi)
|
||||
VOSK=$(realpath vosk)
|
||||
OPENFST=$(realpath openfst)
|
||||
CLAPACK_WASM=$(realpath clapack-wasm)
|
||||
OPENBLAS=$(realpath OpenBLAS)
|
||||
|
||||
cd src &&
|
||||
MODE=0 && # 0: Debug, 1: Optimized release
|
||||
COMMON_FLAGS="Util.cc CommonModel.cc Recognizer.cc Bindings.cc -std=c++23 -Wall -Wextra -Wpedantic -fno-rtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DMAX_WORKERS="$MAX_THREADS" -sWASMFS -sWASM_BIGINT -sMODULARIZE -sWASM_EXNREF -sTEXTDECODER=2 -sWASM_WORKERS=2 -sEVAL_CTORS=2 -sINITIAL_MEMORY="$INITIAL_MEMORY" -sALLOW_MEMORY_GROWTH -sPOLYFILL=0 -sEXIT_RUNTIME=0 -sINVOKE_RUN=0 -sINCOMING_MODULE_JS_API=wasmMemory,instantiateWasm,wasm -sEXPORT_NAME=loadVosklet -sMALLOC=emmalloc -sENVIRONMENT=web,worker -I. -I"$VOSK"/src -L"$KALDI"/src -l:online2/kaldi-online2.a -l:decoder/kaldi-decoder.a -l:ivector/kaldi-ivector.a -l:gmm/kaldi-gmm.a -l:tree/kaldi-tree.a -l:feat/kaldi-feat.a -l:cudamatrix/kaldi-cudamatrix.a -l:lat/kaldi-lat.a -l:lm/kaldi-lm.a -l:rnnlm/kaldi-rnnlm.a -l:hmm/kaldi-hmm.a -l:nnet3/kaldi-nnet3.a -l:transform/kaldi-transform.a -l:matrix/kaldi-matrix.a -l:fstext/kaldi-fstext.a -l:util/kaldi-util.a -l:base/kaldi-base.a -L"$OPENFST"/lib -l:libfst.a -l:libfstngram.a -L"$CLAPACK_WASM" -l:CBLAS/lib/cblas.a -l:CLAPACK-3.2.1/lapack.a -l:CLAPACK-3.2.1/libcblaswr.a -l:f2c_BLAS-3.8.0/blas.a -l:libf2c/libf2c.a -L"$VOSK"/src -l:vosk.a -lembind -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals --pre-js ../Examples/Wrapper.js -o ../test.js"
|
||||
COMMON_FLAGS="Util.cc CommonModel.cc Recognizer.cc Bindings.cc -std=c++23 -Wall -Wextra -Wpedantic -fno-rtti -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 -DMAX_WORKERS="$MAX_THREADS" -sWASMFS -sWASM_BIGINT -sMODULARIZE -sWASM_EXNREF -sTEXTDECODER=2 -sWASM_WORKERS=2 -sEVAL_CTORS=2 -sINITIAL_MEMORY="$INITIAL_MEMORY" -sALLOW_MEMORY_GROWTH -sPOLYFILL=0 -sEXIT_RUNTIME=0 -sINVOKE_RUN=0 -sINCOMING_MODULE_JS_API=wasmMemory,instantiateWasm,wasm -sEXPORT_NAME=loadVosklet -sMALLOC=emmalloc -sENVIRONMENT=web,worker -I. -I"$VOSK"/src -L"$KALDI"/src -l:online2/kaldi-online2.a -l:decoder/kaldi-decoder.a -l:ivector/kaldi-ivector.a -l:gmm/kaldi-gmm.a -l:tree/kaldi-tree.a -l:feat/kaldi-feat.a -l:cudamatrix/kaldi-cudamatrix.a -l:lat/kaldi-lat.a -l:lm/kaldi-lm.a -l:rnnlm/kaldi-rnnlm.a -l:hmm/kaldi-hmm.a -l:nnet3/kaldi-nnet3.a -l:transform/kaldi-transform.a -l:matrix/kaldi-matrix.a -l:fstext/kaldi-fstext.a -l:util/kaldi-util.a -l:base/kaldi-base.a -L"$OPENFST"/lib -l:libfst.a -l:libfstngram.a -L"$OPENBLAS" -l:lib/libopenblas.a -L"$VOSK"/src -l:vosk.a -lembind -msimd128 -matomics -mbulk-memory -mreference-types -mnontrapping-fptoint -mextended-const -msign-ext -mmutable-globals --pre-js ../Examples/Wrapper.js -o ../test.js"
|
||||
echo "Mode = $MODE" &&
|
||||
if [ "$MODE" = 0 ]; then
|
||||
em++ $COMMON_FLAGS -O0 -sRUNTIME_DEBUG -sDISABLE_EXCEPTION_CATCHING=0 -sSTACK_OVERFLOW_CHECK=2 -sASSERTIONS=2 -g3
|
||||
elif [ "$MODE" = 1 ]; then
|
||||
em++ $COMMON_FLAGS -O3 --closure 1 &&
|
||||
tr -d '\n' < ../test.js | tr -s ' ' > /tmp/hehe && mv /tmp/hehe ../test.js
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user