在 MacOS 上跑 kaldi


categories: asr

tags: C++ asr kaldi

在MacOS 下跑 kaldi

bash 复制代码
brew install automake llvm cmake sox libtool subversion

基本安装

Common build problems · pyenv/pyenv Wiki;

bash 复制代码
brew install pyenv
pyenv install -v 2.7.18

# Set the python version.

pyenv global 2.7.18
# Export PATH if necessary.

export PATH="$(pyenv root)/shims:${PATH}"
Add if necessary.:

echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc

还得是用 xcode 的 sdk, brew 很多都显示找不到对应的包, 用了 CPPFLAG也不行

bash 复制代码
 ==> /opt/homebrew/bin/pyenv install 2.7.18
Downloading openssl-1.1.1v.tar.gz...
-> https://www.openssl.org/source/openssl-1.1.1v.tar.gz
Installing openssl-1.1.1v...
Installed openssl-1.1.1v to /Users/zorch/.pyenv/versions/2.7.18
Downloading readline-8.0.tar.gz...
-> https://ftpmirror.gnu.org/readline/readline-8.0.tar.gz
Installing readline-8.0...
Installed readline-8.0 to /Users/zorch/.pyenv/versions/2.7.18
Downloading Python-2.7.18.tar.xz...
-> https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tar.xz
Installing Python-2.7.18...
patching file configure
patching file configure.ac
patching file setup.py
patching file 'Mac/Tools/pythonw.c'
patching file setup.py
patching file 'Doc/library/ctypes.rst'
patching file 'Lib/test/test_str.py'
patching file 'Lib/test/test_unicode.py'
patching file 'Modules/_ctypes/_ctypes.c'
patching file 'Modules/_ctypes/callproc.c'
patching file 'Modules/_ctypes/ctypes.h'
patching file 'Modules/_ctypes/callproc.c'
patching file setup.py
patching file 'Mac/Modules/qt/setup.py'
patching file setup.py
python-build: use zlib from xcode sdk
Installed Python-2.7.18 to /Users/zorch/.pyenv/versions/2.7.18

还需要加入环境变量

bash 复制代码
 ==> pyenv global 2.7.18
  √  ~/code/c-cpp_proj/kaldi/tools
 ==> python2
Python 2.7.18 (default, Dec 16 2023, 14:23:06)
[GCC Apple LLVM 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

 ==> which python2
/Users/zorch/.pyenv/shims/python2

安装 openblas

gfortran 11 ARM-darwin (Apple M1) build failure · Issue #3222 · OpenMathLib/OpenBLAS;

改版本

bash 复制代码
 ==> vi extras/install_openblas.sh

OPENBLAS_VERSION=0.3.20

之前是 0.3.13

bash 复制代码
 ==> sw_vers -productVersion
14.1
 √  ~/code/c-cpp_proj/kaldi/tools
 ==> MACOSX_DEPLOYMENT_TARGET=14.1 extras/install_openblas.sh

结果

bash 复制代码
 OpenBLAS build complete. (BLAS CBLAS LAPACK LAPACKE)

  OS               ... Darwin
  Architecture     ... arm64
  BINARY           ... 64bit
  C compiler       ... CLANG  (cmd & version : Apple clang version 15.0.0 (clang-1500.1.0.2.5))
  Fortran compiler ... GFORTRAN  (cmd & version : GNU Fortran (Homebrew GCC 13.2.0) 13.2.0)
-n   Library Name     ... libopenblas_armv8-r0.3.20.a
 (Single-threading)
WARNING: If you plan to use the dynamic library libopenblas_armv8-r0.3.20.dylib, you must run:

"make PREFIX=/your_installation_path/ install".

(or set PREFIX in Makefile.rule and run make install.
If you want to move the .dylib to a new location later, make sure you change
the internal name of the dylib with:

install_name_tool -id /new/absolute/path/to/libopenblas_armv8-r0.3.20.dylib libopenblas_armv8-r0.3.20.dylib

To install the library, you can run "make PREFIX=/path/to/your/installation install".

/Applications/Xcode.app/Contents/Developer/usr/bin/make -j 11 -f Makefile.install install
Generating openblas_config.h in /Users/zorch/code/c-cpp_proj/kaldi/tools/OpenBLAS/install/include
Generating f77blas.h in /Users/zorch/code/c-cpp_proj/kaldi/tools/OpenBLAS/install/include
Generating cblas.h in /Users/zorch/code/c-cpp_proj/kaldi/tools/OpenBLAS/install/include
Copying LAPACKE header files to /Users/zorch/code/c-cpp_proj/kaldi/tools/OpenBLAS/install/include
Copying the static library to /Users/zorch/code/c-cpp_proj/kaldi/tools/OpenBLAS/install/lib
Copying the shared library to /Users/zorch/code/c-cpp_proj/kaldi/tools/OpenBLAS/install/lib
Generating openblas.pc in /Users/zorch/code/c-cpp_proj/kaldi/tools/OpenBLAS/install/lib/pkgconfig
Generating OpenBLASConfig.cmake in /Users/zorch/code/c-cpp_proj/kaldi/tools/OpenBLAS/install/lib/cmake/openblas
Generating OpenBLASConfigVersion.cmake in /Users/zorch/code/c-cpp_proj/kaldi/tools/OpenBLAS/install/lib/cmake/openblas
Install OK!
OpenBLAS is installed successfully.

issue 永远滴神

检验

bash 复制代码
 ==> extras/check_dependencies.sh
extras/check_dependencies.sh: all OK.

正餐开始

bash 复制代码
# optional, exec if you have built the old version
# make -j clean depend
cd src/
./configure --use-cuda=no
make -j11

跑一个例子试试

bash 复制代码
cd egs/yesno/s5
 ==> make test -j10

更新: 2024-11-06

最新的编译不用这么麻烦了, 安装python2 之后直接用 cmake 安装即可(看 INSTALL.md)

bash 复制代码
vi cmake/INSTALL.md

## Build with Ninja Generator
```bash
mkdir -p build && cd build
cmake -GNinja -DCMAKE_INSTALL_PREFIX=../dist ..
cmake --build . --target install
```

执行之后会在`./dist/bin` 中生成可执行的工具

安装之后有个小坑, 我这里环境是 MacOS14.6 的, m2 , 执行下面的测试脚本之后提示 dylib 找不到

bash 复制代码
cd  egs/yesno/s5
./run.sh

dyld[90630]: Library not loaded: @rpath/libfstscript.16.dylib
  Referenced from: <6A97203D-EF56-3A63-A568-9B24B38894CF> /Users/xx/code/asr_learning/kaldi/dist/bin/fstcompile
  Reason: no LC_RPATH's found
zsh: abort

但是这个共享库是存在的, 后来问了一下 GPT, 用下面的脚本给填了一下 rpath 就可以执行了

bash 复制代码
for i in `ls -l ~/code/asr_learning/kaldi/dist/bin | tr -s ' ' | cut  -d' ' -f9`; 
do
install_name_tool -add_rpath /Users/x/code/asr_learning/kaldi/dist/lib "/Users/x/code/asr_learning/kaldi/dist/bin/$i" ;
done

注意这里用绝对路径, 否则找不到, 用户名改成自己的.

最后的部分日志信息.

c 复制代码
fstdeterminizestar --use-log=true
fsttablecompose data/lang_test_tg/L_disambig.fst data/lang_test_tg/G.fst
fstminimizeencoded
fstpushspecial
fstisstochastic data/lang_test_tg/tmp/LG.fst
0.534295 0.533859
[info]: LG not stochastic.
fstcomposecontext --context-size=1 --central-position=0 --read-disambig-syms=data/lang_test_tg/phones/disambig.int --write-disambig-syms=data/lang_test_tg/tmp/disambig_ilabels_1_0.int data/lang_test_tg/tmp/ilabels_1_0.6521 data/lang_test_tg/tmp/LG.fst
fstisstochastic data/lang_test_tg/tmp/CLG_1_0.fst
0.534295 0.533859
[info]: CLG not stochastic.
make-h-transducer --disambig-syms-out=exp/mono0a/graph_tgpr/disambig_tid.int --transition-scale=1.0 data/lang_test_tg/tmp/ilabels_1_0 exp/mono0a/tree exp/mono0a/final.mdl
fstminimizeencoded
fsttablecompose exp/mono0a/graph_tgpr/Ha.fst data/lang_test_tg/tmp/CLG_1_0.fst
fstdeterminizestar --use-log=true
fstrmsymbols exp/mono0a/graph_tgpr/disambig_tid.int
fstrmepslocal
fstisstochastic exp/mono0a/graph_tgpr/HCLGa.fst
0.5342 -0.000144671
HCLGa is not stochastic
add-self-loops --self-loop-scale=0.1 --reorder=true exp/mono0a/final.mdl exp/mono0a/graph_tgpr/HCLGa.fst
steps/decode.sh --nj 1 --cmd utils/run.pl exp/mono0a/graph_tgpr data/test_yesno exp/mono0a/decode_test_yesno
decode.sh: feature type is delta
steps/diagnostic/analyze_lats.sh --cmd utils/run.pl exp/mono0a/graph_tgpr exp/mono0a/decode_test_yesno
steps/diagnostic/analyze_lats.sh: see stats in exp/mono0a/decode_test_yesno/log/analyze_alignments.log
Overall, lattice depth (10,50,90-percentile)=(1,1,1) and mean=1.1
steps/diagnostic/analyze_lats.sh: see stats in exp/mono0a/decode_test_yesno/log/analyze_lattice_depth_stats.log
local/score.sh --cmd utils/run.pl data/test_yesno exp/mono0a/graph_tgpr exp/mono0a/decode_test_yesno
local/score.sh: scoring with word insertion penalty=0.0,0.5,1.0
%WER 0.00 [ 0 / 232, 0 in , 0 del, 0  ub ] exp/mono0a/decode_te t_ye no/wer_11_1.0

wer=0

相关推荐
fengye2071613 小时前
实验:CPython 迭代协议底层验证(`PyObject_GetIter` / `PyIter_Next`)
macos
DevLoom_12 小时前
macOS 命令行 curl/git 报 SSL 证书错误?eMudhra 事件完整修复指南
git·macos·ssl
清水白石00817 小时前
Python 安装与环境配置:Windows、macOS、Linux 完整指南(第2集)
windows·python·macos
hhhjhl18 小时前
开源鸿蒙平台 CMP 三方库「compose-macos-26-ui」适配全流程
macos·开源·harmonyos
七牛云行业应用1 天前
DeepSeek Harness(dsh)安装完整指南:Windows、macOS、Linux 三平台 + 桌面端与 Web 端全覆盖
linux·windows·macos·ai·ai编程
全栈探索者2 天前
一枚 162MB 的挂件,改写一只猫的画风:LoRA 实战——风格定制与人脸保持
人工智能·macos·lora·aigc·stablediffusion·comfyui
福大大架构师每日一题2 天前
ollama v0.40.11发布:macOS原生语音生成上线,d3决策模型正式加入
macos·策略模式
小天源2 天前
智叟云集系统:便携部署、MAC 授权与交付排障
macos
Joy T2 天前
voice-dump-to-todo:把混乱的语音整理成可执行待办,一个实用的 Agent Skill
ide·macos·语音识别·xcode·任务管理·自研skill
JPower_mr.g2 天前
SmartCall v1.0.9 发布:智能体知识库上线,让 AI 客服先查资料再回答
java·ide·人工智能·macos·架构·开源·xcode