0)初めに
OS は CentOS6 で、FreePBX のものです。
以下のサイトを参考にさせていただきました。ありがとうございます。
http://server-setting.info/centos/open-jtalk-install.html
http://d.hatena.ne.jp/leetmikeal/20130403/1364959490
http://www.xucker.jpn.org/pc/ffmpeg_wav.html
http://www.ksknet.net/cat28/mimeparser.html
http://d.hatena.ne.jp/ksmemo/20090111/p1
https://hgotoh.jp/wiki/doku.php/documents/mail/mail-005
http://blog.glidenote.com/blog/2012/08/02/incron/
1)テキストファイルを音声ファイルに変換できるようにする
1-1)コンパイル用のライブラリを整える
ライブラリで不足分をインストールすることと、FFmpeg コンパイル用に cmake のバージョンを2.8.8以上にする必要があります。
# yum update # yum install zlib zlib-devel curl curl-devel bzip2 bzip2- devel libarchive libarchive-devel expat expat-devel qt qt-devel # wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar. gz # tar xzvf cmake-2.8.10.2.tar.gz # cd cmake-2.8.10.2 # ./bootstrap --prefix=/usr/local/cmake-2.8.10. 2 --system-libs # make && make install # cd /usr/local # ln -sfn cmake-2.8.10.2 cmake # vi /etc/bashrc
export PATH=
で、始まる行を
export PATH=/usr/local/cmake/bin:$PATH
に、
export MANPATH=
で、始まる行を
export MANPATH=/usr/local/cmake/man:$MANPATH
に、書き換えて保存します。
~/.bash_profile のパスも同様に書き換えておきます。
その後、コンパイルするために一度実行してパスを書き換えておきます。
# export PATH=/usr/local/cmake/bin:$PATH # export MANPATH=/usr/local/cmake/man:$MANPATH
1-2)libiconv.so.2 を認識させる
# vi /etc/ld.so.conf
/usr/local/lib の1行を書き加える
# ldconfig
1-3)Open JTalk をインストール
各リンクは正しいとは限りません。サイトでリンクの確認を行ってください。
hts-engine : https://sourceforge.net/projects/hts-engine/files/hts_engine%20API/
Open JTalk : https://sourceforge.net/projects/open-jtalk/files/Open%20JTalk/
# cd /usr/local/src # wget https://sourceforge.net/projects/hts-engine/files/l atest/download?source=files # mv download?source=files hts_engine_API-1.10.tar.gz # tar xzvf hts_engine_API-1.10.tar.gz # cd hts_engine_API-1.10 # ./configure # make # make install # cd .. # wget https://sourceforge.net/projects/open-jtalk/files/latest/download?source=files # mv download open_jtalk-1.09.tar.gz # tar xzvf open_jtalk-1.09.tar.gz # cd open_jtalk-1.09 # ./configure --with-hts-engine-header-path=/ussr/local/include --with-hts-engine-library-path=/usr/local/lib --with-charset=UTFF-8 # make # make install # cd .. # wget https://sourceforge.net/projects/open-jtalk/files/HTS%20voice/hts_voice_nitech_jp_atr503_m001-1.05/hts_voice_nitech_jp_atr503_m001-1.05.tar.gz/download # mv download hts_voice_nitech_jp_atr503_m001-1.05.tar.gz # wget https://sourceforge.net/projects/mmdagent/files/MMDAgent_Example/MMDAgent_Example-1.6/MMDAgent_Example-1.6.zip/download # mv download MMDAgent_Example-1.6.zip # unzip -q MMDAgent_Example-1.6.zip # tar xzvf hts_voice_nitech_jp_atr503_m001-1.05.tar.gz # mkdir /var/lib/open_jtalk # chmod a+r /var/lib/open_jtalk # cp hts_voice_nitech_jp_atr503_m001-1.05/nitech_jp_atr503_m001.htsvoice /var/lib/open_jtalk/ # cp MMDAgent_Example-1.6/Voice/mei/*.htsvoice /var/lib/open_jtalk/ # chmod a+r /var/lib/open_jtalk -Rf
1-4) ffmpeg のインストール
# yum -y install autoconf automake bzip2 cmake f reetype-devel gcc gcc-c++ git wget libtool make mercurial nasm pkgconfig zlib-devel # vi ffmpeg_build.sh
ファイルの中身は以下の通りです。(http://www.jifu-labo.net/2015/09/ffmpeg_build/ からの転載)
#!/bin/sh cpu_core=2 enable_h264=1 enable_h265=1 enable_vp8=1 enable_aac=1 enable_mp3=1 enable_ogg=1 enable_opus=1 enable_ass=1 src_dir="$HOME/ffmpeg_sources" prefix_dir="/usr/local/ffmpeg_build" export PATH=$prefix_dir/bin:$PATH export PKG_CONFIG_PATH="$prefix_dir/lib/pkgconfig" enable_option="" repo_yasm="git://github.com/yasm/yasm.git" repo_x264="https://git.videolan.org/git/x264.git" repo_x265="https://github.com/videolan/x265.git" repo_aac="git://git.code.sf.net/p/opencore-amr/fdk-aac" repo_opus="git://github.com/xiph/opus.git" repo_libvpx="https://chromium.googlesource.com/webm/libvpx.git" repo_libass="https://github.com/libass/libass.git" repo_ffmpeg="git://source.ffmpeg.org/ffmpeg" url_autoconf="http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz" url_lame="http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz" url_ogg="http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz" url_theora="http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2" url_vorbis="http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz" print_error() { echo "error: $1" } run_git() { repo="$1" opt="$2" dir=${repo##*/} dir=${dir%.git} if [ -d $dir ]; then cd $dir && git pull if [ $? -ne 0 ]; then print_error "git pull $dir" && exit 1 fi else git clone $opt $repo if [ $? -ne 0 ]; then print_error "git clone $dir" && exit 1 fi cd $dir fi } run_wget() { url="$1" file=${url##*/} dir=${file%.tar.*} if [ ! -e $file ]; then wget $url if [ $? -ne 0 ]; then print_error "wget $file" && exit 1 fi fi case $file in *.gz) tar xvzf $file ;; *.bz2) tar xvjf $file ;; esac cd $dir } uid=`id | sed 's/uid=([0-9]+)(.+/1/'` if [ $uid -ne 0 ];then print_error "not root user" exit 1 fi mkdir -p $src_dir mkdir -p $prefix_dir aconf_ver=`LANG=C autoconf -V | head -n 1 | sed -e "s/autoconf (GNU Autoconf) ([0-9]*).([0-9]*)/12/"` if [ $aconf_ver -lt 269 ]; then echo "---------- build autoconf ----------" run_wget $url_autoconf ./configure --prefix="$prefix_dir" --bindir="$prefix_dir/bin" make make install make distclean fi echo "---------- build Yasm ----------" cd $src_dir run_git $repo_yasm "--depth 1" autoreconf -fiv ./configure --prefix="$prefix_dir" --bindir="$prefix_dir/bin" make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make yasm" && exit 1 fi make install make distclean if [ $enable_h264 -eq 1 ]; then echo "---------- build libx264 ----------" cd $src_dir run_git $repo_x264 "" ./configure --prefix="$prefix_dir" --bindir="$prefix_dir/bin" --enable-static make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make libx264" && exit 1 fi make install make distclean enable_option="${enable_option} --enable-libx264" fi if [ $enable_h265 -eq 1 ]; then echo "---------- build libx265 ----------" cd $src_dir run_git $repo_x265 "" cd build/linux cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$prefix_dir" -DENABLE_SHARED:bool=off ../../source make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make libx265" && exit 1 fi make install make clean enable_option="${enable_option} --enable-libx265" fi if [ $enable_aac -eq 1 ]; then echo "---------- build libfdk_aac ----------" cd $src_dir run_git $repo_aac "--depth 1" autoreconf -fiv ./configure --prefix="$prefix_dir" --disable-shared make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make libfdk_aac" && exit 1 fi make install make distclean enable_option="${enable_option} --enable-libfdk-aac" fi if [ $enable_mp3 -eq 1 ]; then echo "---------- build libmp3lame ----------" cd $src_dir run_wget $url_lame ./configure --prefix="$prefix_dir" --bindir="$prefix_dir/bin" --disable-shared --enable-nasm make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make libmp3lame" && exit 1 fi make install make distclean enable_option="${enable_option} --enable-libmp3lame" fi if [ $enable_opus -eq 1 ]; then echo "---------- build libopus ----------" cd $src_dir run_git $repo_opus "" ./autogen.sh ./configure --prefix="$prefix_dir" --disable-shared make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make libopus" && exit 1 fi make install make distclean enable_option="${enable_option} --enable-libopus" fi if [ $enable_ogg -eq 1 ]; then echo "---------- build libogg ----------" cd $src_dir run_wget $url_ogg ./configure --prefix="$prefix_dir" --disable-shared make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make libogg" && exit 1 fi make install make distclean echo "---------- build libvorbis ----------" cd $src_dir run_wget $url_vorbis LDFLAGS="-L$prefix_dir/lib" CPPFLAGS="-I$prefix_dir/include" ./configure --prefix="$prefix_dir" --with-ogg="$prefix_dir" --disable-shared make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make libvorbis" && exit 1 fi make install make distclean enable_option="${enable_option} --enable-libvorbis" echo "---------- build libtheora ----------" cd $src_dir run_wget $url_theora ./configure --prefix="$prefix_dir" --disable-shared make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make libtheora" && exit 1 fi make install make clean enable_option="${enable_option} --enable-libtheora" fi if [ $enable_vp8 -eq 1 ]; then echo "---------- build libvpx ----------" cd $src_dir run_git $repo_libvpx "--depth 1" ./configure --prefix="$prefix_dir" --disable-examples make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make libvpx" && exit 1 fi make install make clean enable_option="${enable_option} --enable-libvpx" fi if [ $enable_ass -eq 1 ]; then echo "---------- build libass ----------" cd $src_dir run_git $repo_libass "--depth 1" autoreconf -fiv ./configure --prefix="$prefix_dir" --disable-shared make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make libass" && exit 1 fi make install make clean enable_option="${enable_option} --enable-libass" fi echo "---------- build FFmpeg ----------" cd $src_dir run_git $repo_ffmpeg "--depth 1" ./configure --prefix="$prefix_dir" --extra-cflags="-I$prefix_dir/include" --extra-ldflags="-L$prefix_dir/lib" --bindir="$prefix_dir/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfreetype $enable_option make -j${cpu_core} if [ $? -ne 0 ]; then print_error "make ffmpeg" && exit 1 fi make install make distclean hash -r
実行権限を与えて実行
# chmod u+x ffmpeg_build.sh # sh ./ffmpeg_build.sh
これで、
ffmpeg -i 入力ファイル名 -ac 1 -ar 8000 出力ファイル名
で、Open_JTalk が出力した 48000Hz のファイルを 8000Hz のモノラルに変更できます。
Open_JTalk で直接 8000Hz の周波数で音声ファイルを出力すると、間延びして聞き取れないものが出来上がるので、FFmpegで変換するわけです。
1-5)テキスト wav 変換スクリプトの作成
# vi /bin/TextSpeach
ファイルの中身は以下の通りです。
#!/bin/bash cat $1 | tr -d 'r' | tr -d 'n' > $1.tmp open_jtalk -m /var/lib/open_jtalk/nitech_jp_atr503_m001.htsvoice -x /usr/local/dic -ow $2.tmp $1.tmp # cp $2 $2.tmp ffmpeg -i $2.tmp -ac 1 -ar 8000 -y $2 rm -f $2.tmp
実行権の設定
# chmod a+x /bin/TextSpeach