Java Freetts不适用于外部扬声器
我已经在java应用程序中使用了Freetts.jar文件来宣布令牌号。我的应用程序在我的笔记本电脑上运行良好,但在有外置扬声器的桌面电脑上无法运行。我得到一个空指针异常。注意:我在两台计算机上都使用Windows 7 下面的代码是我使用的示例格式Java Freetts不适用于外部扬声器,java,freetts,Java,Freetts,我已经在java应用程序中使用了Freetts.jar文件来宣布令牌号。我的应用程序在我的笔记本电脑上运行良好,但在有外置扬声器的桌面电脑上无法运行。我得到一个空指针异常。注意:我在两台计算机上都使用Windows 7 下面的代码是我使用的示例格式 package tsapp; import java.util.Locale; import javax.speech.Central; import javax.speech.synthesis.Synthesizer; import javax
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();
}
}
}
我们能做一件简单的事吗:
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);
}
}
只需确保所有这些LIB也都在您的桌面上。您可以使用MaryTTS,更好;)谢谢你的建议。但是我想知道是什么原因导致了我的应用程序中的错误。你能提供一段正在运行的简单代码让我们测试它吗?也许这和资源分配或内部事务有关谢谢你Saulius先生。但是你能解释一下我犯的错误吗?我怀疑你没有把所有的库复制到你的桌面上。另外,下次请提供例外,然后我可以说更多关于这个问题,并尝试编写简单的代码,因为这样你们可以得到打赌结果。我不是FreeTTS的专家,因此我不能评论任何其他内容。谢谢你的帮助,Saulius先生