亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復錯誤“無法投射到 com.sun.speech.freetts

如何修復錯誤“無法投射到 com.sun.speech.freetts

繁花不似錦 2021-12-10 10:20:59
我試圖在我的 Java 程序(來自https://freetts.sourceforge.io/docs/index.php)中使用 FreeTTS并且我收到此錯誤:java.lang.ClassCastException: com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory cannot be cast to com.sun.speech.freetts.VoiceDirectory我嘗試將免費 TTS jar 文件重新添加到我的項目中,這是我的代碼:import com.sun.speech.freetts.Voice;import com.sun.speech.freetts.VoiceManager;public class TextToSpeech {//String voiceName = "kevin16";VoiceManager freeVM;Voice voice;public TextToSpeech(String words) {    freeVM = VoiceManager.getInstance();    voice = VoiceManager.getInstance().getVoice("kevin16");    if (voice != null) {        voice.allocate();//Allocating Voice    }    try {        voice.setRate(190);//Setting the rate of the voice        voice.setPitch(150);//Setting the Pitch of the voice        voice.setVolume(3);//Setting the volume of the voice        SpeakText(words);// Calling speak() method    } catch (Exception e1) {        e1.printStackTrace();    }}public void SpeakText(String words) {    voice.speak(words);}我TextToSpeech從另一個類調用構造函數,如下所示: new TextToSpeech("Hello World");將不勝感激任何幫助或建議!
查看完整描述

2 回答

?
月關寶盒

TA貢獻1772條經驗 獲得超5個贊

像這樣更改 TextToSpeech 構造函數:


public TextToSpeech(String words) {

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

    voice = VoiceManager.getInstance().getVoice("kevin16");

    if (voice != null) {

        voice.allocate();// Allocating Voice

        try {

            voice.setRate(190);// Setting the rate of the voice

            voice.setPitch(150);// Setting the Pitch of the voice

            voice.setVolume(3);// Setting the volume of the voice

            SpeakText(words);// Calling speak() method


        } catch (Exception e1) {

            e1.printStackTrace();

        }


    } else {

        throw new IllegalStateException("Cannot find voice: kevin16");

    }

}

這個想法是指示 freetts 使用com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory類而不是AlanVoiceDirectory類。


查看完整回答
反對 回復 2021-12-10
?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

代碼更改:


而不是以下行


freeVM = VoiceManager.getInstance();

voice = VoiceManager.getInstance().getVoice("kevin16");

修改為


freeVM = VoiceManager.getInstance();

voice = freeVM.getVoice("kevin16");


查看完整回答
反對 回復 2021-12-10
  • 2 回答
  • 0 關注
  • 319 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號