LoginSignup
4
4

More than 3 years have passed since last update.

ESPnet をMacbookに実装

Last updated at Posted at 2020-04-25

経緯

オープンソースの音声認識ライブラリをMacで使いたっかたのですが、いろいろサーベイした結果、できるかどうかの結論すらわかりませんでした。
Requirement environments according to ESPnet official documents

Supported Linux distributions and other requirements
We support the following Linux distributions with CI. If you want to build your own Linux by yourself, please also check our CI configurations. to prepare the appropriate environments
ubuntu18
ubuntu16
centos7
debian9

(ドキュメンテーションではLinuxのみ動作可能に見えますがmacOSに実装できました)
ここで自分のやり方&出現した問題をまとめます。

手順

動作環境

macOS Calatina 10.15.4(現時点2020.4の最新バージョン)
Anaconda3(Python3.7.3)

Homebrewインストール

https://brew.sh/index_ja

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

環境の準備

ドキュメンテーションによるとgcc 4.9+ for PyTorch1.0.0+が必要ですが

warp-transducer.done: espnet.done
    rm -rf warp-transducer
    git clone https://github.com/HawkAaron/warp-transducer.git
    # Note: Requires gcc>=5.0 to build extensions with pytorch>=1.0

ESPnetのmakefileを参照するとgcc>=5.0が必要です。

gccをインストール

$ brew install gcc
$ ln -s /usr/local/bin/gcc-9 /usr/local/bin/gcc
$ ln -s /usr/local/bin/g++-9 /usr/local/bin/g++
$ gcc --version
gcc-9 (Homebrew GCC 9.3.0_1) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.

cmakeをインストール

https://cmake.org/download/からmacOSバージョンをダウンロードしてインストール

sox,ffmepg,flacをインストール

$ conda install -c conda-forge sox
$ conda install -c conda-forge ffmpeg
$ brew install flac
$ brew install automake

autoconfをインストール

http://ftp.gnu.org/gnu/autoconf/からダウンロードします。

$ wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.xz
$ tar xvfz autoconf-latest.tar.xz
$ cd autoconf-latest
$ ./configure --prefix=/usr  #ここで権限を取得できなかったらprefixを ~ 以下にしてください.
$ make
$ make install
$ git clone https://github.com/kaldi-asr/kaldi
$ cd kaldi/tools
$ ./extras/install_openblas.sh #openBLAS installation
$ ./extras/check_dependencies.sh 

dependencies全部実装したら

$ make -j <スレッド数>  #ここは異常に遅いので急げれば全てのコアを使ってください。

cudaなしでcompile

$ cd ../src
$ ./configure --mkl-root=/opt/intel/compilers_and_libraries_2020/mac/mkl --use-cuda=no
$ make -j clean depend; make -j <NUM-CPU>

ESPnetインストール

$ git clone https://github.com/espnet/espnet
$ cd espnet/tools

Xcode付属のclangが既にインストールされていた場合、gccコマンドを叩いてもclangが呼ばれてしまいます。clangでコンパイルするとclang: error: unsupported option '-fopenmp'の問題が起こりますのでmakeを行う前にコンパイラーの変数をgccにdefineしなければなりません。

$ export CC=gcc
$ export CXX=g++

$ make KALDI=<PATH_TO_KALDI>  #OPTIONS

OPTIONS:

CUPY_VERSION='' #CPU-onlyでインストールするためcupy versionを空にする.
PYTHON=/opt/anaconda3/bin/python3.7 #minicondaでバグるとPYTHONを指定してください.
TH_VERSION=1.2.0 #macOS用のwarp-ctcパッケージがないためCTC Lossを統合したversion1.2.0以上のpytrochが必要.
INFO: library availableness check start.
INFO: # libraries to be checked = 7
INFO: --> espnet is installed.
INFO: --> kaldiio is installed.
INFO: --> matplotlib is installed.
INFO: --> torch is installed.
INFO: --> chainer is installed.
INFO: --> chainer_ctc is installed.
WARNING: --> warprnnt_pytorch is not installed.
INFO: library availableness check done.
INFO: 6 / 7 libraries are correctly installed.
INFO: please try to setup again and then re-run this script.
make: *** [check_install] Error 1

warprnnt_pytorchはCPU-only platformだといらないみたいのでこれで完成です。

検証

$cd espnet/egs/csj/asr1;bash ../../../utils/recog_wav.sh --models csj.transformer.v1 <wavファイル>

以下はcsj.transformerモデルで日本語のasr結果

stage 0: Data preparation
stage 1: Feature Generation
steps/make_fbank_pitch.sh --cmd run.pl --nj 1 --write_utt2num_frames true decode/osa/data decode/osa/log decode/osa/fbank
steps/make_fbank_pitch.sh: moving decode/osa/data/feats.scp to decode/osa/data/.backup
utils/validate_data_dir.sh: Successfully validated data-directory decode/osa/data
steps/make_fbank_pitch.sh: [info]: no segments file exists: assuming wav.scp indexed by utterance.
steps/make_fbank_pitch.sh: Succeeded creating filterbank and pitch features for data
/Users/soshiyuu/signal/espnet/egs/csj/asr1/../../../utils/dump.sh --cmd run.pl --nj 1 --do_delta false decode/osa/data/feats.scp decode/download/csj.transformer.v1/data/train_nodup_sp/cmvn.ark decode/osa/log decode/osa/dump
stage 2: Json Data Preparation
/Users/soshiyuu/signal/espnet/egs/csj/asr1/../../../utils/data2json.sh --feat decode/osa/dump/feats.scp decode/osa/data decode/osa/dict
/Users/soshiyuu/signal/espnet/egs/csj/asr1/../../../utils/feat_to_shape.sh --cmd run.pl --nj 1 --filetype  --preprocess-conf  --verbose 0 decode/osa/dump/feats.scp decode/osa/data/tmp-EPng1/input_1/shape.scp
sym2int.pl: replacing X with 1
** Replaced 1 instances of OOVs with 1
stage 3: Decoding

Recognized text: えーっと月曜日の午前中などはどうでしょうか空いてるでしょうかえーすーアイアイ山田先生は

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4