ウィンドウも出ないようなスタンドアローンなJavaプログラムをTomcatに持っていってサーブレットから使うようにしたらエラー発生。


java.lang.ArrayStoreException
  at java.lang.System.arraycopy(Native Method)
  at java.util.Vector.toArray(Vector.java:689)
  at com.sun.speech.freetts.UniqueVector.toArray(VoiceManager.java:840)
  at com.sun.speech.freetts.VoiceManager.getVoiceDirectories(VoiceManager.java:203)
  at com.sun.speech.freetts.VoiceManager.getVoices(VoiceManager.java:109)
  at com.sun.speech.freetts.VoiceManager.getVoice(VoiceManager.java:519)

スタンドアローンのときは特に何も設定しなくても動いていたのに。

FreeTTSのソースコードを見たところ、どうやら FreeTTS の JAR ファイルから声情報(VoiceDirectoryの派生クラス)をうまく取得できていない様子。

Tomcat の起動時にシステムプロパティ -Dfreetts.voices=com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory,com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory を設定することで回避できた。

また、


# voices
com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory
com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory

というようにVoiceDirectoryの派生クラス名を列挙しておいて(行頭が#はコメント扱い)

-Dfreetts.voicesfile=voicesfile.txt

システムプロパティ freetts.voicesfile にファイルのパスを指定することでもOKらしい(未確認)。

このへんのキーワードで検索してみたら、ドキュメントにそれらしいことが書いてあった。

Installing Voice Packages

Voice Packages can be added to FreeTTS without any compilation. There are two ways to alert FreeTTS to the presence of a new voice:

1. Listing of the VoiceDirectory classes that are loaded.
2. Putting the packages in the correct directory and allowing FreeTTS to automatically detect them. [[[TODO: This is not yet implemented. For now use the listing method.]]]

Listing of the VoiceDirectory classes requires all of the required classes to be appropriately in the java classpath. The names of the voice directory classes are listed in voices files. When VoiceManager.getVoices() is called, reads several files.

1. First, it looks for internal_voices.txt, stored in the same directory as VoiceManager.class (If the VoiceManager is in a jarfile, which it probably is, then this file is also inside the jar file). If the file does not exist, FreeTTS moves on. internal_voices.txt only exists to allow one to package FreeTTS into a single stand-alone jarfile, as may be needed for applets. Avoid using internal_voices.txt if at all possible. The file then requires you to ship all listed voices along with FreeTTS and provides minimal flexibility.
2. Next, FreeTTS looks for voices.txt in the same directory as freetts.jar (assuming FreeTTS is being executed from a jar, which it probably is). If the file does not exist, FreeTTS moves on.
3. Last, if the system property "freetts.voicesfile" is defined, then FreeTTS will use the voice directory classes listed in that file.

Voice packages can also be recognized simply by putting them in the correct filesystem directory. [[[TODO: At least, that is the plan. This is not yet actually implemented.]]] If a jarfile is in the correct directory and has the "FreeTTSVoiceDefinition: true" definition in its Manifest, then it is assumed to be a voice package. The file is then loaded along with all dependencies listed in the "Class-Path:" definition. Whatever class is listed as the "Main-Class:" is assumed to be the voice directory. There are two ways to specify which filesystem directory to look in:

1. By default, FreeTTS will look in the same directory as freetts.jar. (Assuming FreeTTS was loaded from a jarfile, which it probably was).
2. The directories specified by the system property "freetts.voicespath".

FreeTTS Programmer's Guide

Ref.
-FreeTTS で音声合成に挑戦
-FreeTTS で日本語に対応してみる

tags: zlashdot Text2Speech FreeTTS Java Text2Speech

Posted by NI-Lab. (@nilab)