Beaglebone Blackをしゃべれるようにする

RasPiでも去年よく試されていたので、新味はまったくないのだけど、OpenJTalkを入れてみる。
出力は、とりあえずUSB DACを使うのもUSBポートがめんどくさいので、HDMIから音声を分岐するアダプタを使う。

OpenJTalkのインストール

OpenJTalk関連パッケージをインストールする。

ubuntu@ubuntu-armhf:~$ sudo apt-get install open-jtalk libhtsengine1 open-jtalk-mecab-naist-jdic
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  hts-voice-nitech-jp-atr503-m001
The following NEW packages will be installed:
  libhtsengine1 open-jtalk open-jtalk-mecab-naist-jdic
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 14.9 MB of archives.
After this operation, 67.5 MB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports/ precise/universe libhtsengine1 armhf 1.05-2 [33.2 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports/ precise/universe open-jtalk armhf 1.04-2 [160 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports/ precise/universe open-jtalk-mecab-naist-jdic all 1.04-2 [14.7 MB]
Fetched 14.9 MB in 43s (341 kB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LANG = "ja_JP.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package libhtsengine1.
(Reading database ... 11177 files and directories currently installed.)
Unpacking libhtsengine1 (from .../libhtsengine1_1.05-2_armhf.deb) ...
Selecting previously unselected package open-jtalk.
Unpacking open-jtalk (from .../open-jtalk_1.04-2_armhf.deb) ...
Selecting previously unselected package open-jtalk-mecab-naist-jdic.
Unpacking open-jtalk-mecab-naist-jdic (from .../open-jtalk-mecab-naist-jdic_1.04-2_all.deb) ...
Setting up libhtsengine1 (1.05-2) ...
Setting up open-jtalk (1.04-2) ...
Setting up open-jtalk-mecab-naist-jdic (1.04-2) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

Perlが途中で言語設定が環境変数にないって怒っているけど、ワーニングなので問題なさげ。

voiceデータがない...

OpenJTalkのおすすめパッケージに"hts-voice-nitech-jp-atr503-m001"が出てくるのだけど、これは今は提供されていないようだ。
htsengineがhtsengine1に変わっているので、依存関係がおかしいのかも。

ubuntu@ubuntu-armhf:~$ sudo apt-get install hts-voice-nitech-jp-atr503-m001 -sReading package lists... Done
Building dependency tree
Reading state information... Done
Package hts-voice-nitech-jp-atr503-m001 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'hts-voice-nitech-jp-atr503-m001' has no installation candidate

voiceデータがないのでは、しゃべれないな。


一般的には、MMDAgentのvoiceデータを使うようなので、それを入れてみる。
http://sourceforge.net/projects/mmdagent/files/MMDAgent_Example/
最新版は、"MMDAgent_Example-1.4 2013-12-25"のようだ。
ライセンスは、それぞれのディレクトリに入っているとある。
ダウンロードして展開し、Voiceファイルを取り出す。

ubuntu@ubuntu-armhf:~$ wget http://downloads.sourceforge.net/project/mmdagent/MMDAgent_Example/MMDAgent_Example-1.4/MMDAgent_Example-1.4.zip

ubuntu@ubuntu-armhf:~$ unzip MMDAgent_Example-1.4.zip
-bash: unzip: command not found

あら、unzipも入ってないのか。入れる。

ubuntu@ubuntu-armhf:~$ apt-get install unzip
ubuntu@ubuntu-armhf:~$ unzip MMDAgent_Example-1.4.zip
Archive:  MMDAgent_Example-1.4.zip
(snip)
   creating: MMDAgent_Example-1.4/Voice/
   creating: MMDAgent_Example-1.4/Voice/mei/
  inflating: MMDAgent_Example-1.4/Voice/mei/COPYRIGHT.txt
  inflating: MMDAgent_Example-1.4/Voice/mei/mei_angry.htsvoice
  inflating: MMDAgent_Example-1.4/Voice/mei/mei_bashful.htsvoice
  inflating: MMDAgent_Example-1.4/Voice/mei/mei_happy.htsvoice
  inflating: MMDAgent_Example-1.4/Voice/mei/mei_normal.htsvoice
  inflating: MMDAgent_Example-1.4/Voice/mei/mei_sad.htsvoice
  inflating: MMDAgent_Example-1.4/Voice/mei/README.txt

meiというボイスデータで、angry, bashful, happy, normal, sadの5種類がある。
ライセンスは、README.txtやCOPYRIGHT.txtを見ると、Creative Commons Attribution 3.0だった。
OpenJTalkでは、voiceデータのある場所で起動することになっているようなので、置き場所はどこでもいい。
htsvoiceというのは、pdf、inf、winなど、いっぱいあった音響モデルデータを、1つにマージしたファイル。

音声データを作成してみる... って、OpenJTalk古い...

OpenJTalkは、オプションをいっぱい指定しないといけないのがめんどくさかったのだけど、現在は音響モデルファイルはhtsvoiceという名前で1つにまとめられているので、それを指定するだけでいいようだ。
データは、オプションの最後にテキストファイルを渡すのがコマンドっぽいのだけど、ダイナミックに作成するときには、パイプで渡せばいいようだ。

ubuntu@ubuntu-armhf:~$ echo "test" | open_jtalk -m /home/ubuntu/MMDAgent_Example-1.4/Voice/mei/mei_normal.htsvoice -x /var/lib/mecab/dic/open-jtalk/naist-jdic -ow /tmp/tmp.wav
ERROR: main() in open_jtalk.c: Invalid option '-m'.

あらら...
mオプションは、OpenJTalkが新しくないとダメみたいだわ...
1.06以降でサポートしたみたい。

ubuntu@ubuntu-armhf:~$ open_jtalk

The Japanese TTS System "Open JTalk"
Open JTalk version 1.04 (http://open-jtalk.sourceforge.net/)
Copyright (C) 2008-2011  Nagoya Institute of Technology
All rights reserved.

1.04ですか、古すぎ...
最新版は、1.07で、2013年12月25日に出ている。
http://open-jtalk.sourceforge.net/


ビルドは、hts_engineとopen-jtalkは最低やらないといけないのか。
http://hts-engine.sourceforge.net/
最新版:hts_engine API version 1.08 (December 25, 2013)
http://downloads.sourceforge.net/project/hts-engine/hts_engine%20API/hts_engine_API-1.08/hts_engine_API-1.08.tar.gz
OpenJTalk 1.07はここ。
http://downloads.sourceforge.net/project/open-jtalk/Open%20JTalk/open_jtalk-1.07/open_jtalk-1.07.tar.gz
makeはすんなり通るようだけど、今のBeaglebone BlackのUbuntu環境には、ビルド環境すらそろっていないので、それを整えるだけで時間かかりそう...


手っ取り早く音声出したいだけなのよ〜。
というわけで、日和って古い音響モデルデータを使うことにする。
ダウンロードできるのは、以下のバージョン。

  • MMDAgent_Example-1.4 2013-12-25
  • MMDAgent_Example-1.3.1 2012-12-25
  • MMDAgent_Example-1.3 2012-08-01
  • MMDAgent_Example-1.1 2011-08-03
  • MMDAgent_Example-1.0 2011-05-01

とりあえず、1.3.1を落としてみる。

ubuntu@ubuntu-armhf:~$ wget http://downloads.sourceforge.net/project/mmdagent/MMDAgent_Example/MMDAgent_Example-1.3.1/MMDAgent_Example-1.3.1.zip
ubuntu@ubuntu-armhf:~$ unzip MMDAgent_Example-1.3.1.zip
ubuntu@ubuntu-armhf:~$ cd MMDAgent_Example-1.3.1/Voice/mei_normal/
ubuntu@ubuntu-armhf:~/MMDAgent_Example-1.3.1/Voice/mei_normal$ ls
COPYRIGHT.txt  gv-mgc.pdf     lf0.win2  mgc.pdf   tree-dur.inf     tree-lpf.inf
README.txt     gv-switch.inf  lf0.win3  mgc.win1  tree-gv-lf0.inf  tree-mgc.inf
dur.pdf        lf0.pdf        lpf.pdf   mgc.win2  tree-gv-mgc.inf
gv-lf0.pdf     lf0.win1       lpf.win1  mgc.win3  tree-lf0.inf

infがたくさん見えるので、これで使えそうだ。

ubuntu@ubuntu-armhf:~/MMDAgent_Example-1.3.1/Voice/mei_normal$ echo "Hi" | open_jtalk -td tree-dur.inf -tf tree-lf0.inf -tm tree-mgc.inf -md dur.pdf -mf lf0.pdf -mm mgc.pdf -dm mgc.win1 -dm mgc.win2 -dm mgc.win3 -df lf0.win1 -df lf0.win2 -df lf0.win3 -dl lpf.win1 -ef tree-gv-lf0.inf -em tree-gv-mgc.inf -cf gv-lf0.pdf -cm gv-mgc.pdf -k gv-switch.inf  -x /var/lib/mecab/dic/open-jtalk/naist-jdic -ow /tmp/tmp.wav
$ ls -l /tmp/
total 36
-rw-rw-r-- 1 ubuntu ubuntu 33644 Mar 12 05:20 tmp.wav

できている。
実際に使うには、s,a,u,jm,jf,jlなどの個別のパラメータを調整してやらないと、聞けるようにはならないようだ。

-s 48000 -p 240 -a 0.58 -u 0.0 -jm 0.7 -jf 0.5 -l -z 48000

作成した音声を再生するプレーヤーが必要

OpenJTalkは、与えられた文字列のWAVファイルを生成するだけ。
これを再生しないといけないのがめんどくさい。
まず、プレーヤーがいる。mpg123を入れる。
というか、ALSAとかの環境も揃ってないのではないかな...
遠い。


ALSAはkernel組み込みで使える状態にあるようだ。

ubuntu@ubuntu-armhf:~$ dmesg
(snip)
[    0.174402] Advanced Linux Sound Architecture Driver Initialized.
(snip)
[    2.735060] ALSA device list:
[    2.738230]   #0: TI BeagleBone Black
(snip)

確かに見えている。

ubuntu@ubuntu-armhf:~$ cat /proc/asound/cards
 0 [Black          ]: TI_BeagleBone_B - TI BeagleBone Black
                      TI BeagleBone Black


aplayも入っていないので、alsa-utilsを入れる。

ubuntu@ubuntu-armhf:~$ sudo apt-get install alsa-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  alsa-base libasound2 libpci3 libsamplerate0 linux-sound-base pciutils
Suggested packages:
  apmd alsa-oss oss-compat libasound2-plugins libasound2-python
The following NEW packages will be installed:
  alsa-base alsa-utils libasound2 libpci3 libsamplerate0 linux-sound-base
  pciutils
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/3230 kB of archives.
After this operation, 6206 kB of additional disk space will be used.
(snip)


再生してみる。

ubuntu@ubuntu-armhf:~$ sudo aplay /tmp/tmp.wav
Playing WAVE '/tmp/tmp.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

再生はしているようだけど、音は出ていない。


alsa.confとかがダメかな。
バイスは見えているみたいだけど。

ubuntu@ubuntu-armhf:~$ sudo aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Black [TI BeagleBone Black], device 0: HDMI nxp-hdmi-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
ubuntu@ubuntu-armhf:~$ sudo aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=Black
    TI BeagleBone Black,
    Default Audio Device
sysdefault:CARD=Black
    TI BeagleBone Black,
    Default Audio Device
dmix:CARD=Black,DEV=0
    TI BeagleBone Black,
    Direct sample mixing device
dsnoop:CARD=Black,DEV=0
    TI BeagleBone Black,
    Direct sample snooping device
hw:CARD=Black,DEV=0
    TI BeagleBone Black,
    Direct hardware device without any conversions
plughw:CARD=Black,DEV=0
    TI BeagleBone Black,
    Hardware device with all software conversions

ALSA設定の大本はここ。/usr/share/alsa/alsa.conf
ほかにも、/etc/asound.confとか、/etc/modprobe.d/alsa-base.confが。


音が短すぎてダメかな?
長めの音を作って再生テスト。

ubuntu@ubuntu-armhf:~$ cd ~/MMDAgent_Example-1.3.1/Voice/mei_normal
ubuntu@ubuntu-armhf:~/MMDAgent_Example-1.3.1/Voice/mei_normal$ echo "a b c d e f g h i j k l m n " | open_jtalk -td tree-dur.inf -tf tree-lf0.inf -tm tree-mgc.inf -md dur.pdf -mf lf0.pdf -mm mgc.pdf -dm mgc.win1 -dm mgc.win2 -dm mgc.win3 -df lf0.win1 -df lf0.win2 -df lf0.win3 -dl lpf.win1 -ef tree-gv-lf0.inf -em tree-gv-mgc.inf -cf gv-lf0.pdf -cm gv-mgc.pdf -k gv-switch.inf  -x /var/lib/mecab/dic/open-jtalk/naist-jdic -ow ~/tmp.wav
ubuntu@ubuntu-armhf:~/MMDAgent_Example-1.3.1/Voice/mei_normal$ cd ~
ubuntu@ubuntu-armhf:~$ ls -l tmp.wav
-rw-rw-r-- 1 ubuntu ubuntu 231884 Mar 12 07:08 tmp.wav
ubuntu@ubuntu-armhf:~$ sudo aplay tmp.wav
Playing WAVE 'tmp.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono

やっぱ音出てね〜。


HDMI生接続に変更。リブートして挑む。
音出てる〜。
もっかいコンバーターに変える。
音出てる〜。
なんだよそれ。
どうも、起動時にHDMI生きてないとダメなタイミングがあるような。
あ、あれか、HDMIスリープするタイミングで切れたら復帰しないのか...
あの問題は、まだ解決してないのだよねぇ...
boot.scr作ればいいのかな...

HDMIのスリープを抑制する

しょうがない、スリープしない対策については、これまで何度か遭遇している。
おそらくkernelの起動オプションでconsoleblank=0を渡してやるとよさげ。
前に遭遇したときには、他の何をやっても無駄だった。


uEnv.txtのoptargsに追記する。

ubuntu@ubuntu-armhf:~$ sudo vi /boot/uboot/uEnv.txt
optargs=fixrtc consoleblank=0

再起動する。kernel起動オプションとして渡っているか確認する。渡っている。

ubuntu@ubuntu-armhf:~$ cat /proc/cmdline
console=ttyO0,115200n8 fixrtc consoleblank=0 root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait

kernelの内部パラメータのブランクするタイマー設定をチェックする。0になっている。

ubuntu@ubuntu-armhf:~$ cat /sys/module/kernel/parameters/consoleblank
0

デフォルトでは600になっているので、スリープの停止に成功した模様。
10分以上経過しても、音は途切れなかった。