首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >线程"main“类中出现异常: com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory java.lang.ClassCastException

线程"main“类中出现异常: com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory java.lang.ClassCastException
EN

Stack Overflow用户
提问于 2020-11-08 23:09:37
回答 1查看 54关注 0票数 0

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

代码语言:javascript
复制
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();
         }
    

     }

 }

但是面临着一个错误。

代码语言:javascript
复制
Exception in thread "main" java.lang.ClassCastException: class com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory
EN

回答 1

Stack Overflow用户

发布于 2020-11-08 23:42:09

可能某些jars链接不正确..当我使用netbeans构建项目时,我就开始工作了!

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

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

  1. 从"freetts-1.2.2-src.zip“(可从sf.net下载)中的"lib”文件夹添加lib/freetts.jar
  2. 将jdk文件夹(如果尚未列出)添加到项目库
  3. !现在运行代码。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64739617

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档