java語音功能

安裝speechsdk51.exe和speechsdk51LanguagePack。exe

安裝方法:

  下載後。先打開 speechsdk51.exe  選擇目錄:C:\speechsdk51  單擊 unzip.   解壓完後。
                到 speechsdk51LangPack.exe  解到C:\speechsdk51LangPack 。
                接下來非常重要。。。注意不要顛倒順序。。  進入C:\speechsdk51  注意是 C:\speechsdk51。。  運行:setup.exe。    完後。
                到C:\speechsdk51LangPack。運行setup.exe。
 接下來,就是導入jar包了  http://download.csdn.net/detail/wsad227/8094283可以到這裏下載jar包  ,裏面有支持64位機和32位機,將64/32。dll放到c:\windows\system32文件夾中



   

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;


public class FileToString {
	 
          public static void main(String[] args) throws IOException {  
         SpeechUtil speechutil = new SpeechUtil();  
//            100表示讀取音量,0表示讀取速度(-10,10之間)  
        speechutil.speakMessage("你好", 100, 1);
       

    }  
}
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;


public class SpeechUtil {
//  message 是需要轉換的文本信息,volume是聲音大小,rate是讀取速度。  
public void speakMessage(String message, int volume, int rate) {  
      
        ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");  
        Dispatch sapo = sap.getObject();  
        try {  
              
            sap.setProperty("Volume", new Variant(volume));  
            sap.setProperty("Rate", new Variant(rate));  
            Dispatch.call(sapo, "Speak", new Object[]{message});  
  
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            sapo.safeRelease();  
            sap.safeRelease();  
        }  
    }  
}

做完上面的全部步驟就可以,讓你的軟件說話了>_<
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章