Java 組み込み音声を使用しようとしていますが、それを使用しようとするたびに、synth.allocate を呼び出すとヌル ポインター例外が発生します。オンラインで例を見てきましたが、それでも同じエラーが発生し、何が間違っているのかわかりません
JButton button = new JButton();
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
try {
Synthesizer synth = Central.createSynthesizer(
new SynthesizerModeDesc(Locale.ENGLISH));
synth.allocate();
synth.resume();
synth.speakPlainText("Hello, world!", null);
synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
synth.deallocate();
} catch (Exception e) {
e.printStackTrace();
}
}
});