java文本到语音(freetts)未知错误

ds97pgxw  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(481)

因此,我正在尝试编写一个非常简单的文本到语音应用程序,显然,我要做的第一件事是获得实际freetts模块的句柄。我使用vscode作为我的ide,据我所知,我已经将正确的.jar文件放在了“引用库”部分。我直接复制了其他人的代码,这些代码应该做同样的事情,但它给了我同样的错误。简而言之,我犯了一个错误,我不知道这意味着什么。
代码如下:

// Imports
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

public class TextToSpeech {

private static Voice[] voices;

public static void main(String[] args) throws Exception {

    VoiceManager vm = VoiceManager.getInstance();
    // Gathers all availible voices
    voices = vm.getVoices();

    // Sets the voice to a kevin voice
    Voice voice = vm.getVoice("kevin");
    voice.allocate();

    voice.speak("Test test test");
    voice.deallocate();

    }
}

错误如下:

Exception in thread "main" java.lang.ClassCastException: class 
com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory cannot be cast to class 
com.sun.speech.freetts.VoiceDirectory (com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory 
is in unnamed module of loader com.sun.speech.freetts.DynamicClassLoader @66048bfd; 
com.sun.speech.freetts.VoiceDirectory is in unnamed module of loader 'app')
        at com.sun.speech.freetts.VoiceManager.getVoices(VoiceManager.java:113)
        at uk.co.softwarepulse.speech.app.TextToSpeech.main(TextToSpeech.java:51)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题