我在我的java应用程序中使用了Freetts.jar文件来宣布令牌号。我的应用程序在我的笔记本电脑上工作得很好,但在有外部扬声器的台式机上却无法工作。我得到一个空指针异常。注意:我在两台电脑上都使用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();
}
}
}发布于 2016-12-19 16:59:36
我们能做一件简单的事吗?

像这样
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);
}
}只要确保所有这些库都在你的桌面上。
https://stackoverflow.com/questions/40924717
复制相似问题