0

我正在尝试开发一个使用 java 中的 freetts 将文本转换为语音的程序。我已经添加了所有必需的 jar 文件和构建路径。

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class TextToSpeech {

     public static void main(String[] args) {
    
    
         Voice voice;//Creating object of Voice class
         voice = VoiceManager.getInstance().getVoice("kevin");//Getting voice
         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 
             voice.speak("Hello world");//Calling speak() method

         }
         catch(Exception e)
         {
             e.printStackTrace();
         }
    

     }

 }

但面临错误。

Exception in thread "main" java.lang.ClassCastException: class com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory
4

1 回答 1

0

可能有些罐子没有正确链接..我使用netbeans构建项目后就开始工作了!

谢谢你们(@netbeans)..你们拯救了我的一天!:)

对于那些可能有同样问题的人,使用 netbeans 来避免库的麻烦。

  1. 从“freetts-1.2.2-src.zip”中的“lib”文件夹添加 lib/freetts.jar(可从 sf.net 下载)
  2. 将 jdk 文件夹(如果尚未列出)添加到项目库
  3. 你完成了!现在运行代码。
于 2020-11-08T15:42:09.377 回答