2

トークン番号を通知する Java アプリケーションで Freetts.jar ファイルを使用しました。アプリケーションはラップトップでは問題なく動作しますが、外部スピーカーを備えたデスクトップでは動作しません。null ポインター例外が発生します。注: 両方のコンピューターで Windows 7 を使用しています。

以下のコードは、私が使用したサンプル形式です。

package tsapp;

import java.util.Locale;
import javax.speech.Central;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.swing.JOptionPane;
public class TextSpeech {
 public static void main(String[] args){
 try
 {
   System.setProperty("freetts.voices",
    "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");

   Central.registerEngineCentral
    ("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
   Synthesizer  synthesizer =
    Central.createSynthesizer(new SynthesizerModeDesc(Locale.US));
   synthesizer.allocate();
   synthesizer.resume();
   String str;

        str=JOptionPane.showInputDialog(null,"Voice Check");
        if(str==null)
        return;
        synthesizer.speakPlainText(str, null);
   synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
   synthesizer.deallocate();
  }
   catch(Exception e)
   {
       System.out.println(e.getClass());
     e.printStackTrace();
   }
 }
}
4

1 に答える 1

1

簡単なことを 1 つ実行できますか。

  1. バイナリをダウンロードhttps://netix.dl.sourceforge.net/project/freetts/FreeTTS/FreeTTS%201.2.2/freetts-1.2.2-bin.zip
  2. プロジェクトに追加ここに画像の説明を入力
  3. 簡単なコードを書きます。

このような

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

public class TestVoice {


    public static void main(String[] args) {

        String text = "Voice check!";

        Voice voice;
        VoiceManager voiceManager = VoiceManager.getInstance();
        voice = voiceManager.getVoice("kevin");
        voice.allocate();
        voice.speak(text);

    }

}

これらすべてのライブラリがデスクトップにもあることを確認してください。

于 2016-12-19T16:59:36.997 に答える