0

我正在尝试在 java 程序中使用mbrola声音,但是没有特定的方法可以在我的 java 程序中包含 mbrola。它在下面的代码中工作正常

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class Mainn {
public static void main(String args[]) {
    final String VOICENAME_kevin = "kevin16";
    final String text; // string to speech
    //System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
     Voice voice;
    VoiceManager voiceManager = VoiceManager.getInstance();
    voice = voiceManager.getVoice(VOICENAME_kevin);
voice.allocate();
 String newText = "first name ";
   boolean status= voice.speak(newText);
   System.out.println("Status"+"  "+status);   
    }
}

但是当我尝试使用 mbrola base 下载 mbr301h.zip 和语音 zip 文件并尝试运行下面的程序代码时

public class Mainn {
public static void main(String args[]) {
    final String VOICENAME_mbrola="mbrola_us1";

    final String text; // string to speech
    
    System.setProperty("mbrola.base", "/home/tech/mbrola");

    Voice voice;
    VoiceManager voiceManager = VoiceManager.getInstance();

    voice = voiceManager.getVoice(VOICENAME_kevin);

    voice.allocate();
 
    String newText = "first name ";
   boolean status= voice.speak(newText);
   System.out.println("Status"+"  "+status);   
    }
}

我正面临像这样的错误

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 @51e2adc7; com.sun.speech.freetts.VoiceDirectory is in unnamed module of loader 'app')
    at com.sun.speech.freetts.VoiceManager.getVoices(VoiceManager.java:113)
    at com.sun.speech.freetts.VoiceManager.getVoice(VoiceManager.java:502)
    at voice.Mainn.main(Mainn.java:21)

请帮我在 ubuntu 中为一个简单的 java 程序设置 mbrola。

4

0 回答 0