俊星的BLOG

          freetts初探

          FreeTTS是一個語音合成庫,今天進行了相關(guān)的試用。
          1、下載完畢之后,構(gòu)建工程,拷貝到LIB中的JAR有:en_us.jar、freetts.jar、jsapi.jar、freetts-jsapi10.jar
          2、jsapi.jar因為采用的授權(quán)不同于freetts,所以需要運行jsapi.exe并同意后來獲取
          3、需要將speech.properties拷貝到user.home或者java.home/lib下
          4、編寫基于JSAPI的HelloWorld程序:
          import java.util.Locale;

          import javax.speech.Central;
          import javax.speech.EngineList;
          import javax.speech.synthesis.Synthesizer;
          import javax.speech.synthesis.SynthesizerModeDesc;
          import javax.speech.synthesis.Voice;

          public class HelloWorld {

              
          public HelloWorld() {
              }

              
          public static void listAllVoices(String modeName) {
                  System.out.println(
          "All " + modeName + " Mode JSAPI Synthesizers and Voices:");
                  SynthesizerModeDesc required 
          = new SynthesizerModeDesc(null, modeName, Locale.US, nullnull);
                  EngineList engineList 
          = Central.availableSynthesizers(required);
                  
          for (int i = 0; i < engineList.size(); i++) {
                      SynthesizerModeDesc desc 
          = (SynthesizerModeDesc) engineList.get(i);
                      System.out.println(
          "    " + desc.getEngineName() + " (mode=" + desc.getModeName() + ", locale="
                              
          + desc.getLocale() + "):");
                      Voice voices[] 
          = desc.getVoices();
                      
          for (int j = 0; j < voices.length; j++)
                          System.out.println(
          "        " + voices[j].getName());
                  }
              }

              
          public static void main(String args[]) {
                  
          // 利用 FreeTTS 讀出Good job
                  try {
                      SynthesizerModeDesc desc 
          = new SynthesizerModeDesc("FreeTTS en_US general synthesizer""general",
                              Locale.US, 
          nullnull);
                      Synthesizer synthesizer 
          = Central.createSynthesizer(desc);
                      
          if (synthesizer == null) {
                          System.exit(
          1);
                      }
                      synthesizer.allocate();
                      synthesizer.resume();
                      desc 
          = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
                      Voice voices[] 
          = desc.getVoices();
                      
          for (Voice v : voices) {
                          synthesizer.getSynthesizerProperties().setVoice(v);
                          synthesizer.speakPlainText(
          "good job"null);
                          synthesizer.waitEngineState(
          0x10000L);
                      }
                      synthesizer.deallocate();
                  } 
          catch (Exception ex) {
                      ex.printStackTrace();
                  }
              }
          }

          5、編寫基于FreeTTS的測試程序:
          import com.sun.speech.freetts.Voice;
          import com.sun.speech.freetts.VoiceManager;

          public class FreeTTSHelloWorld {

              
          public FreeTTSHelloWorld() {
              }

              
          public static void listAllVoices() {
                  System.out.println();
                  System.out.println(
          "All voices available:");
                  VoiceManager voiceManager 
          = VoiceManager.getInstance();
                  Voice voices[] 
          = voiceManager.getVoices();
                  
          for (int i = 0; i < voices.length; i++)
                      System.out.println(
          "    " + voices[i].getName() + " (" + voices[i].getDomain() + " domain)");

              }

              
          public static void main(String args[]) {
                  listAllVoices();
                  System.out.println();
                  VoiceManager voiceManager 
          = VoiceManager.getInstance();
                  Voice helloVoice 
          = voiceManager.getVoice("kevin16");
                  
          if (helloVoice == null) {
                      System.exit(
          1);
                  }
                  helloVoice.allocate();
                  helloVoice.speak(
          "GOOD JOB KINKDING");
                  helloVoice.deallocate();
                  System.exit(
          0);
              }
          }

          posted on 2010-10-15 11:28 俊星 閱讀(3429) 評論(2)  編輯  收藏

          評論

          # re: freetts初探 2011-06-02 22:16 瓏兒

          System property "mbrola.base" is undefined. Will not use MBROLA voices.

          這個問題怎么解決啊?  回復(fù)  更多評論   

          # re: freetts初探 2012-02-01 17:12 apiao

          學(xué)習(xí)了! 就是不清楚為啥在eclipse下跑不起來...  回復(fù)  更多評論   


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 雷波县| 东乌珠穆沁旗| 建平县| 石家庄市| 阳朔县| 富蕴县| 淮安市| 太湖县| 宁乡县| 乐至县| 五华县| 迭部县| 昭平县| 响水县| 拉孜县| 崇阳县| 靖安县| 大埔区| 年辖:市辖区| 民权县| 阳城县| 江北区| 黄骅市| 冕宁县| 玛纳斯县| 新乡县| 玉门市| 铜陵市| 工布江达县| 临清市| 连州市| 佛教| 苏尼特右旗| 赣州市| 吴川市| 日照市| 广丰县| 宜兴市| 承德县| 从江县| 金昌市|