gpt4 book ai didi

java - FreeTTS java.lang.NullPointerException

转载 作者:行者123 更新时间:2023-12-02 11:59:33 25 4
gpt4 key购买 nike

我正在尝试制作一个文本转语音程序,但我总是得到这个:

Exception in thread "main" java.lang.NullPointerException
at FreeTTS.main(FreeTTS.java:7)

这是我的代码:

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class FreeTTS {
public static void main(String args[]) {
VoiceManager vm = VoiceManager.getInstance();
Voice voice = vm.getVoice("kevin16");
voice.allocate();
voice.speak("Hello World!");
voice.deallocate();
}
}

我该如何解决这个问题?

最佳答案

vm.getVoice("kevin16")

返回null。来自 Javadoc:

Returns: the Voice that has the same name as voiceName if one exists, else null

因此,未找到语音“kevin16”。

关于java - FreeTTS java.lang.NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47368596/

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