Snowboy 是 KITT.AI 開發的一個高度可定制的熱詞檢測引擎,當筆者的 jetson nano 加上話筒后,就立馬嘗試安裝,但在安裝過程中卻發生了錯誤,所以把處理方式記錄了下來以作備忘。
首先,按 Snowboy 官方文檔 編譯安裝 swig-3.0.10 和克隆 snowboy 代碼過程都很順利
sudo apt-get install sox libpcre3 libpcre3-dev libatlas-base-dev pip install pyaudio # 下載 swig-3.0.10,https://sourceforge.net/projects/swig/files/swig/swig-3.0.10/ tar -xvzf swig-3.0.10.tar.gz cd swig-3.0.10/ ./configure --prefix=/usr --without-clisp --without-maximum-compile-warnings make sudo make install sudo install -v -m755 -d /usr/share/doc/swig-3.0.10 sudo cp -v -R Doc/* /usr/share/doc/swig-3.0.10
git clone https://github.com/Kitt-AI/snowboy
但在編譯 snowboy 代碼的 swig/Python3 時發生錯誤
cd swig/Python3 sudo make
出錯信息
../..//lib/ubuntu64/libsnowboy-detect.a: error adding symbols: File in wrong format collect2: error: ld returned 1 exit status Makefile:73: recipe for target '_snowboydetect.so' failed make: *** [_snowboydetect.so] Error 1
google 后,發現原來 Makefile 那里少了對 ARM 的判斷,需要加上下面圖片紅框的判斷:
nano Makefile

判斷的文本:
ifneq (,$(findstring aarch64,$(shell uname -m))) SNOWBOYDETECTLIBFILE = $(TOPDIR)/lib/aarch64-ubuntu1604/libsnowboy-detect.a endif
然后再編譯
sudo make
可以看到編譯成功了
g++ -I../../ -O3 -fPIC -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++0x -shared snowboy-detect-swig.o \ ../..//lib/aarch64-ubuntu1604/libsnowboy-detect.a -L/usr/lib/python3.6/config-3.6m-aarch64-linux-gnu -L/usr/lib -lpython3.6m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions -lm -ldl -lf77blas -lcblas -llapack -latlas -o _snowboydetect.so
再將在 snowboy.kitt.ai 上生成的熱詞放在 examples/Python3 下嘗試運行,又發生了一個錯誤(筆者的熱詞文件為 tortoise.pmdl)
jetbot@jetbot-desktop:~/temp/github/snowboy/examples/Python3$ python3 demo.py tortoise.pmdl Traceback (most recent call last): File "demo.py", line 1, in <module> import snowboydecoder File "/home/jetbot/temp/github/snowboy/examples/Python3/snowboydecoder.py", line 5, in <module> from . import snowboydetect ImportError: attempted relative import with no known parent package
這時需要修改 snowboydecoder.py
nano snowboydecoder.py

把
from . import snowboydetect
替換為
import snowboydetect
最后,再運行一下 demo.py,已經能成功檢測熱詞了
jetbot@jetbot-desktop:~/temp/github/snowboy/examples/Python3$ python3 demo.py rtoise.pmdl Listening... Press Ctrl+C to exit INFO:snowboy:Keyword 1 detected at time: 2020-02-23 09:38:07
參考文章:
