我想使用建立在講話中的Java,但是每當我嘗試使用它時,它會給我一個空指針異常,當我調用synth.allocate。我在例子在網上看了,但我仍然得到同樣的錯誤,我看不到我在做什麼錯你如何使用內置的Java tts?
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();
}
}
});
問:什麼讓你覺得*是*「內置Java TTS」(文本到語音)? – paulsm4 2012-07-17 20:30:40