From eb3cd2fb4318ec74684280f00dcad201d82cb86f Mon Sep 17 00:00:00 2001 From: John Gebbie Date: Fri, 28 Oct 2022 17:44:34 +0100 Subject: [PATCH 1/2] New package: openfst-1.8.2 --- common/shlibs | 1 + srcpkgs/openfst-devel | 1 + srcpkgs/openfst/template | 54 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 120000 srcpkgs/openfst-devel create mode 100644 srcpkgs/openfst/template diff --git a/common/shlibs b/common/shlibs index c1b969e9d0b4..e34a7fce17ed 100644 --- a/common/shlibs +++ b/common/shlibs @@ -4191,3 +4191,4 @@ libabsl_strings.so.2206.0.0 abseil-cpp-20220623.1_1 libabsl_throw_delegate.so.2206.0.0 abseil-cpp-20220623.1_1 libabsl_time_zone.so.2206.0.0 abseil-cpp-20220623.1_1 libabsl_spinlock_wait.so.2206.0.0 abseil-cpp-20220623.1_1 +libfst.so.25 openfst-1.8.2_1 diff --git a/srcpkgs/openfst-devel b/srcpkgs/openfst-devel new file mode 120000 index 000000000000..b4e86ac8d61f --- /dev/null +++ b/srcpkgs/openfst-devel @@ -0,0 +1 @@ +openfst \ No newline at end of file diff --git a/srcpkgs/openfst/template b/srcpkgs/openfst/template new file mode 100644 index 000000000000..f1b571d4bd54 --- /dev/null +++ b/srcpkgs/openfst/template @@ -0,0 +1,54 @@ +# Template file for 'openfst' +pkgname=openfst +version=1.8.2 +revision=1 +build_style=gnu-configure +configure_args=" + --disable-bin + --disable-dependency-tracking + --enable-compact-fsts + --enable-compress + --enable-const-fsts + --enable-far + --enable-linear-fsts + --enable-lookahead-fsts + --enable-mpdt + --enable-ngram-fsts + --enable-pdt + --enable-shared + --enable-static + --with-pic +" +hostmakedepends="autoconf automake libtool texinfo" +short_desc="Finite-state transducers library" +maintainer="John Gebbie " +license="Apache-2.0" +homepage="https://www.openfst.org" +distfiles="https://www.openfst.org/twiki/pub/FST/FstDownload/openfst-$version.tar.gz" +checksum=de987bf3624721c5d5ba321af95751898e4f4bb41c8a36e2d64f0627656d8b42 + +post_extract() { + # Don't run test during build. + vsed -i configure.ac -e '152,184 d' + # Remove -msse check confused by cross compiling. + vsed -i src/include/fst/float-weight.h -e '120 d' +} + +pre_configure() { + if [ "${XBPS_TARGET_MACHINE%%-musl}" = i686 ]; then + CXXFLAGS+=" -msse" + fi + autoreconf -fi +} + +openfst-devel_package() { + depends="${sourcepkg}>=${version}_${revision}" + short_desc+=" -- development files" + pkg_install() { + vmove usr/include + vmove "usr/lib/*.a" + vmove "usr/lib/*.so" + vmove "usr/lib/fst/*.a" + vmove "usr/lib/fst/*.so" + } +} From 81bdb74b7f0cc2ea0cd2bf551ddf8af45bc4e178 Mon Sep 17 00:00:00 2001 From: John Gebbie Date: Fri, 28 Oct 2022 17:57:26 +0100 Subject: [PATCH 2/2] New package: vosk-api-0.3.43 --- common/shlibs | 1 + .../patches/kaldi-openblas-to-0.3.21.patch | 55 ++++++ .../patches/kaldi-openfst-to-1.8.2.patch | 181 ++++++++++++++++++ srcpkgs/vosk-api/template | 79 ++++++++ srcpkgs/vosk-model-small-en-us | 1 + 5 files changed, 317 insertions(+) create mode 100644 srcpkgs/vosk-api/patches/kaldi-openblas-to-0.3.21.patch create mode 100644 srcpkgs/vosk-api/patches/kaldi-openfst-to-1.8.2.patch create mode 100644 srcpkgs/vosk-api/template create mode 120000 srcpkgs/vosk-model-small-en-us diff --git a/common/shlibs b/common/shlibs index e34a7fce17ed..36bf4b749805 100644 --- a/common/shlibs +++ b/common/shlibs @@ -4192,3 +4192,4 @@ libabsl_throw_delegate.so.2206.0.0 abseil-cpp-20220623.1_1 libabsl_time_zone.so.2206.0.0 abseil-cpp-20220623.1_1 libabsl_spinlock_wait.so.2206.0.0 abseil-cpp-20220623.1_1 libfst.so.25 openfst-1.8.2_1 +libvosk.so vosk-api-0.3.43_1 diff --git a/srcpkgs/vosk-api/patches/kaldi-openblas-to-0.3.21.patch b/srcpkgs/vosk-api/patches/kaldi-openblas-to-0.3.21.patch new file mode 100644 index 000000000000..4ae3aac80393 --- /dev/null +++ b/srcpkgs/vosk-api/patches/kaldi-openblas-to-0.3.21.patch @@ -0,0 +1,55 @@ +--- a/src/matrix/cblas-wrappers.h ++++ b/src/matrix/cblas-wrappers.h +@@ -383,10 +383,10 @@ inline void mul_elements( + // add clapack here + #if !defined(HAVE_ATLAS) + inline void clapack_Xtptri(KaldiBlasInt *num_rows, float *Mdata, KaldiBlasInt *result) { +- stptri_(const_cast("U"), const_cast("N"), num_rows, Mdata, result); ++ stptri_(const_cast("U"), const_cast("N"), num_rows, Mdata, result, 1, 1); + } + inline void clapack_Xtptri(KaldiBlasInt *num_rows, double *Mdata, KaldiBlasInt *result) { +- dtptri_(const_cast("U"), const_cast("N"), num_rows, Mdata, result); ++ dtptri_(const_cast("U"), const_cast("N"), num_rows, Mdata, result, 1, 1); + } + // + inline void clapack_Xgetrf2(KaldiBlasInt *num_rows, KaldiBlasInt *num_cols, +@@ -420,7 +420,7 @@ inline void clapack_Xgesvd(char *v, char *u, KaldiBlasInt *num_cols, + sgesvd_(v, u, + num_cols, num_rows, Mdata, stride, + sv, Vdata, vstride, Udata, ustride, +- p_work, l_work, result); ++ p_work, l_work, result, 1, 1); + } + inline void clapack_Xgesvd(char *v, char *u, KaldiBlasInt *num_cols, + KaldiBlasInt *num_rows, double *Mdata, KaldiBlasInt *stride, +@@ -430,25 +430,25 @@ inline void clapack_Xgesvd(char *v, char *u, KaldiBlasInt *num_cols, + dgesvd_(v, u, + num_cols, num_rows, Mdata, stride, + sv, Vdata, vstride, Udata, ustride, +- p_work, l_work, result); ++ p_work, l_work, result, 1, 1); + } + // + void inline clapack_Xsptri(KaldiBlasInt *num_rows, float *Mdata, + KaldiBlasInt *ipiv, float *work, KaldiBlasInt *result) { +- ssptri_(const_cast("U"), num_rows, Mdata, ipiv, work, result); ++ ssptri_(const_cast("U"), num_rows, Mdata, ipiv, work, result, 1); + } + void inline clapack_Xsptri(KaldiBlasInt *num_rows, double *Mdata, + KaldiBlasInt *ipiv, double *work, KaldiBlasInt *result) { +- dsptri_(const_cast("U"), num_rows, Mdata, ipiv, work, result); ++ dsptri_(const_cast("U"), num_rows, Mdata, ipiv, work, result, 1); + } + // + void inline clapack_Xsptrf(KaldiBlasInt *num_rows, float *Mdata, + KaldiBlasInt *ipiv, KaldiBlasInt *result) { +- ssptrf_(const_cast("U"), num_rows, Mdata, ipiv, result); ++ ssptrf_(const_cast("U"), num_rows, Mdata, ipiv, result, 1); + } + void inline clapack_Xsptrf(KaldiBlasInt *num_rows, double *Mdata, + KaldiBlasInt *ipiv, KaldiBlasInt *result) { +- dsptrf_(const_cast("U"), num_rows, Mdata, ipiv, result); ++ dsptrf_(const_cast("U"), num_rows, Mdata, ipiv, result, 1); + } + #else + inline void clapack_Xgetrf(MatrixIndexT num_rows, MatrixIndexT num_cols, diff --git a/srcpkgs/vosk-api/patches/kaldi-openfst-to-1.8.2.patch b/srcpkgs/vosk-api/patches/kaldi-openfst-to-1.8.2.patch new file mode 100644 index 000000000000..7bfb73cb5de8 --- /dev/null +++ b/srcpkgs/vosk-api/patches/kaldi-openfst-to-1.8.2.patch @@ -0,0 +1,181 @@ +diff --git a/src/base/kaldi-types.h b/src/base/kaldi-types.h +index 7ebf4f853..c376604a4 100644 +--- a/src/base/kaldi-types.h ++++ b/src/base/kaldi-types.h +@@ -39,24 +39,21 @@ typedef float BaseFloat; + // we find in the future lacks stdint.h + #include + +-// for discussion on what to do if you need compile kaldi +-// without OpenFST, see the bottom of this this file +-#include ++#include // for ssize_t. ++#include // for ?int*_t. + +-namespace kaldi { +- using ::int16; +- using ::int32; +- using ::int64; +- using ::uint16; +- using ::uint32; +- using ::uint64; +- typedef float float32; +- typedef double double64; +-} // end namespace kaldi ++using int8 = int8_t; ++using int16 = int16_t; ++using int32 = int32_t; ++using int64 = int64_t; ++ ++using uint8 = uint8_t; ++using uint16 = uint16_t; ++using uint32 = uint32_t; ++using uint64 = uint64_t; + + // In a theoretical case you decide compile Kaldi without the OpenFST + // comment the previous namespace statement and uncomment the following +-/* + namespace kaldi { + typedef int8_t int8; + typedef int16_t int16; +@@ -70,6 +67,5 @@ namespace kaldi { + typedef float float32; + typedef double double64; + } // end namespace kaldi +-*/ + + #endif // KALDI_BASE_KALDI_TYPES_H_ +diff --git a/src/configure b/src/configure +index c74d67af8..84286da01 100755 +--- a/src/configure ++++ b/src/configure +@@ -929,7 +929,7 @@ fi + OPENFST_VER=${OPENFST_VER:-$(grep 'PACKAGE_VERSION' $FSTROOT/Makefile | sed -e 's:.*= ::')} + OPENFST_VER_NUM=$(echo $OPENFST_VER | sed 's/\./ /g' | xargs printf "%d%02d%02d") + if [ $OPENFST_VER_NUM -lt 10600 ]; then +- failure "OpenFst-$OPENFST_VER is not supported. You need OpenFst >= 1.6.0.)" ++ : + fi + echo "OPENFSTINC = $FSTROOT/include" >> kaldi.mk + if $static_fst ; then +diff --git a/src/fstext/kaldi-fst-io-inl.h b/src/fstext/kaldi-fst-io-inl.h +index f7bb3a7c2..01047919c 100644 +--- a/src/fstext/kaldi-fst-io-inl.h ++++ b/src/fstext/kaldi-fst-io-inl.h +@@ -99,7 +99,7 @@ void ReadFstKaldi(std::istream &is, bool binary, + fst->DeleteStates(); + string line; + size_t nline = 0; +- string separator = FLAGS_fst_field_separator + "\r\n"; ++ string separator = FST_FLAGS_fst_field_separator + "\r\n"; + while (std::getline(is, line)) { + nline++; + vector col; +diff --git a/src/fstext/lattice-weight.h b/src/fstext/lattice-weight.h +index 7637c4d1c..2d82c5647 100644 +--- a/src/fstext/lattice-weight.h ++++ b/src/fstext/lattice-weight.h +@@ -396,8 +396,8 @@ inline bool ApproxEqual(const LatticeWeightTpl &w1, + template + inline std::ostream &operator <<(std::ostream &strm, const LatticeWeightTpl &w) { + LatticeWeightTpl::WriteFloatType(strm, w.Value1()); +- CHECK(FLAGS_fst_weight_separator.size() == 1); +- strm << FLAGS_fst_weight_separator[0]; // comma by default; ++ CHECK(FST_FLAGS_fst_weight_separator.size() == 1); ++ strm << FST_FLAGS_fst_weight_separator[0]; // comma by default; + // may or may not be settable from Kaldi programs. + LatticeWeightTpl::WriteFloatType(strm, w.Value2()); + return strm; +@@ -405,9 +405,9 @@ inline std::ostream &operator <<(std::ostream &strm, const LatticeWeightTpl + inline std::istream &operator >>(std::istream &strm, LatticeWeightTpl &w1) { +- CHECK(FLAGS_fst_weight_separator.size() == 1); ++ CHECK(FST_FLAGS_fst_weight_separator.size() == 1); + // separator defaults to ',' +- return w1.ReadNoParen(strm, FLAGS_fst_weight_separator[0]); ++ return w1.ReadNoParen(strm, FST_FLAGS_fst_weight_separator[0]); + } + + +@@ -728,8 +728,8 @@ inline CompactLatticeWeightTpl Divide(const CompactLatticeW + template + inline std::ostream &operator <<(std::ostream &strm, const CompactLatticeWeightTpl &w) { + strm << w.Weight(); +- CHECK(FLAGS_fst_weight_separator.size() == 1); +- strm << FLAGS_fst_weight_separator[0]; // comma by default. ++ CHECK(FST_FLAGS_fst_weight_separator.size() == 1); ++ strm << FST_FLAGS_fst_weight_separator[0]; // comma by default. + for(size_t i = 0; i < w.String().size(); i++) { + strm << w.String()[i]; + if (i+1 < w.String().size()) +@@ -745,8 +745,8 @@ inline std::istream &operator >>(std::istream &strm, CompactLatticeWeightTpl > + template + inline void TrivialFactorWeightFst::InitStateIterator( + StateIteratorData *data) const { +- data->base = fst::make_unique > >(*this); ++ data->base = std::make_unique > >(*this); + } + + +diff --git a/src/lat/kaldi-lattice.cc b/src/lat/kaldi-lattice.cc +index 648e67115..70fde5acf 100644 +--- a/src/lat/kaldi-lattice.cc ++++ b/src/lat/kaldi-lattice.cc +@@ -114,7 +114,7 @@ class LatticeReader { + CompactLattice *cfst = new CompactLattice(); + string line; + size_t nline = 0; +- string separator = FLAGS_fst_field_separator + "\r\n"; ++ string separator = FST_FLAGS_fst_field_separator + "\r\n"; + while (std::getline(is, line)) { + nline++; + vector col; +diff --git a/src/lat/lattice-functions-transition-model.cc b/src/lat/lattice-functions-transition-model.cc +index 6172610dc..a8cd7b7e2 100644 +--- a/src/lat/lattice-functions-transition-model.cc ++++ b/src/lat/lattice-functions-transition-model.cc +@@ -248,13 +248,13 @@ bool TestWordAlignedLattice(const WordAlignLatticeLexiconInfo &lexicon_info, + int32 num_paths = 5, seed = Rand(), max_path_length = -1; + BaseFloat delta = 0.2; // some lattices have large costs -> use large delta. + +- FLAGS_v = GetVerboseLevel(); // set the OpenFst verbose level to the Kaldi ++ FST_FLAGS_v = GetVerboseLevel(); // set the OpenFst verbose level to the Kaldi + // verbose level. + if (!RandEquivalent(clat, aligned_clat, num_paths, delta, seed, max_path_length)) { + KALDI_WARN << "Equivalence test failed during lattice alignment."; + return false; + } +- FLAGS_v = 0; ++ FST_FLAGS_v = 0; + + return (num_err == 0); + } +diff --git a/src/makefiles/linux_clapack.mk b/src/makefiles/linux_clapack.mk +index e6f4f541d..15292fed1 100644 +--- a/src/makefiles/linux_clapack.mk ++++ b/src/makefiles/linux_clapack.mk +@@ -15,7 +15,7 @@ endif + + CLAPACKLIBS = $(CLAPACKROOT)/CLAPACK-3.2.1/lapack.a $(CLAPACKROOT)/CLAPACK-3.2.1/libcblaswr.a \ + $(CLAPACKROOT)/CBLAS/lib/cblas.a \ +- $(CLAPACKROOT)/f2c_BLAS-3.8.0/blas.a $(CLAPACKROOT)/libf2c/libf2c.a ++ $(CLAPACKROOT)/f2c_BLAS-3.8.0/blas.a + + CXXFLAGS = -std=c++17 -I.. -isystem $(OPENFSTINC) -O1 $(EXTRA_CXXFLAGS) \ + -Wall -Wno-sign-compare -Wno-unused-local-typedefs \ diff --git a/srcpkgs/vosk-api/template b/srcpkgs/vosk-api/template new file mode 100644 index 000000000000..ecd601306c3b --- /dev/null +++ b/srcpkgs/vosk-api/template @@ -0,0 +1,79 @@ +# Template file for 'vosk-api' +pkgname=vosk-api +version=0.3.43 +revision=1 +create_wrksrc=yes +build_wrksrc="vosk-api-${version}/src" +_openfst_commit=7dfd808194105162f20084bb4d8e4ee4b65266d5 +_kaldi_commit=6417ac1dece94783e80dfbac0148604685d27579 +build_style=gnu-makefile +make_use_env=yes +make_build_args="KALDI_ROOT=../../kaldi-${_kaldi_commit} + OPENFST_ROOT=../../kaldi-${_kaldi_commit}/tools/openfst + OPENBLAS_ROOT=../../kaldi-${_kaldi_commit}/tools/OpenBLAS/install" +makedepends="blas-devel lapack-devel openblas-devel libgomp-devel openfst-devel" +short_desc="Offline speech recognition toolkit" +maintainer="John Gebbie " +license="Apache-2.0" +homepage="https://alphacephei.com/vosk" +distfiles="https://github.com/alphacep/vosk-api/archive/v${version}/vosk-api-${version}.tar.gz +https://github.com/alphacep/kaldi/archive/${_kaldi_commit}.tar.gz +https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip" +checksum="50fa82bfbfe3fc5be868237c84ac180eb55da0b65b1803bf022899673afda024 +4e5c08c9c61bbc995e0620321feb0973bb0321442f1bd8f08b47497f55efadda +30f26242c4eb449f948e42cb302dd7a686cb29a3423a8367f99ff41780942498" +shlib_provides="libvosk.so" +patch_args="-d kaldi-${_kaldi_commit} -Np1" + +if [ "$XBPS_TARGET_LIBC" = musl ]; then + makedepends+=" libexecinfo-devel" +fi + +post_extract() { + # Don't need Fortran to C, we have lapack not clapack. + cd "${wrksrc}/kaldi-${_kaldi_commit}/src" + vsed -i configure -e 's/ -l:libf2c\.a//' + cd "${wrksrc}/vosk-api-${version}/src" + vsed -i Makefile -e '/libblas\.a \\/ {N; s/ \\.*//}' + vsed -i Makefile -e 's/ -lf2c//' + + cd "${wrksrc}/kaldi-${_kaldi_commit}/tools" + mkdir -p OpenBLAS/install/lib + ln -sf "${XBPS_CROSS_BASE}/usr/include/openblas" OpenBLAS/install/include + ln -sf "${XBPS_CROSS_BASE}/usr/lib/"* OpenBLAS/install/lib + mkdir -p openfst/include openfst/lib + ln -sf "${XBPS_CROSS_BASE}/usr/include/fst" openfst/include + ln -sf "${XBPS_CROSS_BASE}/usr/lib/"* openfst/lib +} + +pre_build() { + cd "${wrksrc}/kaldi-${_kaldi_commit}/src" + ./configure ${CROSS_BUILD:+--host="${XBPS_CROSS_TRIPLET}"} --mathlib=OPENBLAS_CLAPACK --shared --use-cuda=no + make online2 lm rnnlm +} + +do_install() { + cd "${wrksrc}/vosk-api-${version}/src" + vinstall vosk_api.h 644 usr/include + vinstall libvosk.so 644 usr/lib +} + +do_check() { + cd "${wrksrc}/vosk-api-${version}/c" + ln -sf "${wrksrc}/vosk-model-small-en-us-0.15" model + ln -sf ../python/example/test.wav . + ldflags="-fopenmp -L../src -lvosk -ldl -lpthread -Wl,-rpath,../src" + if [ "$XBPS_TARGET_LIBC" = musl ]; then + ldflags+=" -lexecinfo" + fi + make LDFLAGS="$ldflags" + ./test_vosk | grep -q '"text" : "zero one eight zero three"' +} + +vosk-model-small-en-us_package() { + short_desc="Lightweight english language model" + pkg_install() { + vmkdir usr/share/vosk-models + mv "${wrksrc}/vosk-model-small-en-us-0.15" "${PKGDESTDIR}/usr/share/vosk-models/small-en-us" + } +} diff --git a/srcpkgs/vosk-model-small-en-us b/srcpkgs/vosk-model-small-en-us new file mode 120000 index 000000000000..db9953d33676 --- /dev/null +++ b/srcpkgs/vosk-model-small-en-us @@ -0,0 +1 @@ +vosk-api \ No newline at end of file