gpt4 book ai didi

java - 语音合成空指针异常

转载 作者:行者123 更新时间:2023-12-01 06:17:13 24 4
gpt4 key购买 nike

我得到空指针异常,我也知道原因。这是因为合成器获得空值。我应该怎么做才能删除这个?请帮忙

public class HelloWorld {

public static void main(String args[]) {
try {
// Create a synthesizer for English
Synthesizer synth = Central.createSynthesizer(new SynthesizerModeDesc(Locale.ENGLISH));

// Get it ready to speak
synth.allocate();

synth.resume();

// Speak the "Hello world" string

synth.speakPlainText("Intiallizing the components, we are online and ready,sir", null);

// Wait till speaking is done

synth.waitEngineState(Synthesizer.QUEUE_EMPTY);

// Clean up

synth.deallocate();

} catch (Exception e) {

e.printStackTrace();

}

}

最佳答案

即使在代码中包含所有 jar 文件之后,您也应该为字典设置属性并设置引擎。您可以通过在 try 中包含此代码块来完成此操作:

System.setProperty("freetts.voices","com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");

关于java - 语音合成空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21747089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com