FreeTTS實現語音合成-----將IRC訊息轉換成聽得見的語音

來源:互聯網
上載者:User

本文將展示如何建立一個跨平台的IRC機器人(一個自動化的用戶端),它使用FreeTTS Java語音合成庫來將IRC訊息轉換成聽得見的語音。  FreeTTS庫可以在freetts.sourceforge.net下載。為了串連到 IRC伺服器上,你需要在www.jibble.org/pircbot.php下載PircBot Java IRC API。  當你下載了所需的兩個庫之後,建立一個lib目錄,然後將下列.jar檔案拷貝到裡面。  ·cmu_time_awb.jar

  ·cmu_us_kal.jar

  ·cmulex.jar

  ·cmutimelex.jar

  ·en_us.jar

  ·freetts.jar

  ·pircbot.jar   現在,寫IRC機器人已經變成了一個簡單的任務,因為這些庫將為你完成多數的困難工作。建立一個名為SpeechBot.java的檔案:

  import org.jibble.pircbot.*;

  import com.sun.speech.freetts.*;

  import com.sun.speech.freetts.audio.*;

  import javax.sound.sampled.*;

  import java.io.File;

public class SpeechBot {

      private Voice voice;

  public  SpeechBot(String say) {

  //setName(name); // Choose the voice for the speech synthesizer.

  // 選擇語音合成器的話音

  String voiceName = "kevin16";

  VoiceManager voiceManager = VoiceManager.getInstance();

  voice = voiceManager.getVoice(voiceName);

    if (voice == null) {

  System.out.println("Voice not found.");

  System.exit(1);

  }

     voice.allocate(); // Set up the output format. 分配資源
  // 設定輸出格式
  AudioPlayer voicePlayer = new JavaClipAudioPlayer();

  voicePlayer.setAudioFormat(new AudioFormat(8000, 16, 1, false, true));

  voice.setAudioPlayer(voicePlayer); 


        float wpm = 120f;//設定語速
       voice.setRate(wpm);
       voice.setPitch(85f);
       voice.setPitchRange(10f);
       //合成語音
       voice.startBatch();
       voice.speak(say);
       voice.endBatch();


      //在這裡可以獲得合成語音檔案     

 
       //釋放資源
       voice.deallocate();
  }

  public void onMessage(String channel, String sender,

  String login, String hostname, String message) {

  // Send all IRC messages to the voice

  synthesizer.

  // 發送所有的IRC訊息到語音合成器

  message = message.trim();

  String input = sender + " on " + channel + "

  says: " + message;

  voice.speak(input);

  }

public static void main(String[] args) throws Exception {


  SpeechBot bot = new SpeechBot("SpeechBot");
 
  }}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.