|
| 1 | +# freebsd 12.3 vosk-api build |
| 2 | + |
| 3 | +echo ' |
| 4 | +Build Vosk-API for FreeBSD 12.3 (and possibly later too). |
| 5 | +
|
| 6 | +Please review this script before executing. A number of packages |
| 7 | +will be installed, and some soft links made in /bin and /usr/local/{bin,lib}. |
| 8 | +
|
| 9 | +Expect 20-120 minutes to build everything. Sudo is required for installing |
| 10 | +packages and making soft links. |
| 11 | +
|
| 12 | +Press ^c to exit, or return to start building. |
| 13 | +' |
| 14 | +read junk |
| 15 | + |
| 16 | +set -ex |
| 17 | + |
| 18 | +# pkgs required |
| 19 | +sudo pkg install git cmake gmake libtool automake autoconf autotools \ |
| 20 | + libatomic_ops gsed python38 py38-setuptools py38-wheel py38-pip-run \ |
| 21 | + wget bash curl sox |
| 22 | + |
| 23 | + |
| 24 | +# required: |
| 25 | +# skullduggery soft links to make build run smoother and less patching |
| 26 | +sudo ln -s /usr/local/lib/libatomic_ops.a /usr/lib/libatomic.a |
| 27 | +sudo ln -s /usr/local/bin/bash /bin/bash |
| 28 | +sudo ln -s /usr/local/bin/gmake /usr/local/bin/make |
| 29 | +sudo ln -s /usr/local/bin/python3.8 /usr/local/bin/python3 |
| 30 | +# make sure to pick up our soft link first |
| 31 | +PATH=/usr/local/bin:$PATH |
| 32 | + |
| 33 | + |
| 34 | +# create a build dir for everything |
| 35 | +mkdir build |
| 36 | +cd build |
| 37 | +BUILD_ROOT=$PWD |
| 38 | + |
| 39 | + |
| 40 | +# from here, mostly from vosk-api/travis/Dockerfile.manylinux |
| 41 | +# sed and patch used to include FreeBSD as supported OS and to make minor adjustments |
| 42 | + |
| 43 | +git clone https://github.com/alphacep/vosk-api.git |
| 44 | +git clone -b vosk --single-branch https://github.com/alphacep/kaldi |
| 45 | + |
| 46 | +# Build kaldi tools |
| 47 | +cd $BUILD_ROOT/kaldi/tools |
| 48 | +git clone -b v0.3.13 --single-branch https://github.com/xianyi/OpenBLAS |
| 49 | +git clone -b v3.2.1 --single-branch https://github.com/alphacep/clapack |
| 50 | + |
| 51 | +gmake -C OpenBLAS ONLY_CBLAS=1 DYNAMIC_ARCH=1 TARGET=NEHALEM USE_LOCKING=1 USE_THREAD=0 all |
| 52 | +gmake -C OpenBLAS PREFIX=$PWD/OpenBLAS/install install |
| 53 | + |
| 54 | +mkdir -p clapack/BUILD && cd clapack/BUILD && cmake .. && gmake -j 10 && cp `find . -name "*.a"` ../../OpenBLAS/install/lib |
| 55 | + |
| 56 | +cd $BUILD_ROOT/kaldi/tools |
| 57 | +git clone --single-branch https://github.com/alphacep/openfst openfst |
| 58 | +cd openfst |
| 59 | +autoreconf -i |
| 60 | +CFLAGS="-g -O3" ./configure --prefix=$BUILD_ROOT/kaldi/tools/openfst --enable-static --enable-shared --enable-far --enable-ngram-fsts --enable-lookahead-fsts --with-pic --disable-bin |
| 61 | +gmake -j 10 |
| 62 | +gmake install |
| 63 | + |
| 64 | + |
| 65 | +# Build kaldi main |
| 66 | +cd $BUILD_ROOT/kaldi/src |
| 67 | + |
| 68 | +./configure --mathlib=OPENBLAS_CLAPACK --shared --use-cuda=no |
| 69 | +gsed -i 's:-msse -msse2:-msse -msse2:g' kaldi.mk |
| 70 | +gsed -i 's: -O1 : -O3 :g' kaldi.mk |
| 71 | + |
| 72 | +gmake -j 4 online2 lm rnnlm |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +# Build vosk-api shared lib |
| 77 | + |
| 78 | +cd $BUILD_ROOT/vosk-api/src |
| 79 | +# FreeBSD needs -lexecinfo for python interface |
| 80 | +KALDI_ROOT=$BUILD_ROOT/kaldi EXTRA_LDFLAGS='-lexecinfo' gmake |
| 81 | + |
| 82 | + |
| 83 | +# optional- build and test vosk C interface |
| 84 | +cd $BUILD_ROOT/vosk-api/c |
| 85 | +gmake |
| 86 | + |
| 87 | +wget https://alphacephei.com/kaldi/models/vosk-model-small-en-us-0.15.zip |
| 88 | +unzip vosk-model-small-en-us-0.15.zip |
| 89 | +mv vosk-model-small-en-us-0.15 model |
| 90 | +cp ../python/example/test.wav . |
| 91 | +./test_vosk |
| 92 | + |
| 93 | +# install the python interface |
| 94 | +cd $BUILD_ROOT/vosk-api/python |
| 95 | +# install python module |
| 96 | +sudo python3.8 setup.py install |
| 97 | + |
| 98 | + |
| 99 | +# test the python interface |
| 100 | +cd examples |
| 101 | +# wget https://alphacephei.com/kaldi/models/vosk-model-small-en-us-0.15.zip |
| 102 | +# or, if you tested the vosk C interface, above, just grab the model.zip from there |
| 103 | +cp ../../c/vosk-model-small-en-us-0.15.zip . |
| 104 | +unzip vosk-model-small-en-us-0.15.zip |
| 105 | +mv vosk-model-small-en-us-0.15 model |
| 106 | + |
| 107 | +python3.8 test_simple.py test.wav |
| 108 | + |
| 109 | + |
| 110 | +# clean up soft links |
| 111 | +sudo rm /usr/lib/libatomic.a |
| 112 | +sudo rm /bin/bash |
| 113 | +sudo rm /usr/local/bin/make |
| 114 | +sudo rm /usr/local/bin/python3 |
| 115 | + |
| 116 | +# done |
| 117 | + |
0 commit comments