如何使用Freetts修复错误'classcastexception'

时间:2019-06-18 13:18:15

标签: java text-to-speech freetts

我只想在此代码中使用Freetts测试,但出现错误:

  

ClassCastException:类   com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory不能为   强制转换为com.sun.speech.freetts.VoiceDirectory类   (com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory位于   加载程序com.sun.speech.freetts.DynamicClassLoader的未命名模块   @ 23bc24e9; com.sun.speech.freetts.VoiceDirectory在未命名的模块中   加载程序“ app”)

出什么问题了?

我已经放了图书馆。

import com.sun.speech.freetts.VoiceManager;

public class  Voice {
    private String name;
    private com.sun.speech.freetts.Voice voice;

    public Voice(String name) {
        this.name = name;
        this.voice = VoiceManager.getInstance().getVoice(this.name);
        this.voice.allocate();
    }

    public void say(String something) {
        this.voice.speak(something);
    }

    public static void main(String[] args) {
       Voice voice = new Voice("kevin16");
       String say ="hi";
       voice.say(say);
    }
}

0 个答案:

没有答案