語(yǔ)音實(shí)現(xiàn) “電腦發(fā)音”(英文)一個(gè)很好的觸發(fā)點(diǎn),通過(guò)它可以實(shí)現(xiàn)電子小說(shuō)閱讀、英文聽(tīng)力測(cè)試、英文單詞學(xué)習(xí)... 下面的Speech已對(duì)MSTTS作了簡(jiǎn)單封裝。 1.安裝好MSTTS,可以在windows\speech中打到vtxtauto.lib文件 2.用.Net SDK自帶的tlbimp工具把vtxtauto.tlb轉(zhuǎn)換成.dll格式: tlbimp vtxtauto.tlb /silent /namespace:mstts /out:mstts.dll 這時(shí)的mstts.dll已成為.net framework運(yùn)行庫(kù)的一個(gè)類(lèi)。 3.編寫(xiě)一個(gè)封裝vtxtauto的簡(jiǎn)單類(lèi):Speech . //========================Speech.cs====================== using System; using mstts; //MSTTS名稱(chēng)空間 namespace Bedlang{ //定義名稱(chēng)空間 public class Speech{ private VTxtAuto VTxtAutoEx; public Speech(){ VTxtAutoEx = new VTxtAuto(); VTxtAutoEx.Register(" "," "); //注冊(cè)COM組件 } public void Speak(String text){ VTxtAutoEx.Speak(text, 0); //發(fā)音 } } } //========================Speech.cs====================== 4.編譯Bedlang.Speech csc /target:library /out:Bedlang.dll speech.cs /r:mstts.dll 5.發(fā)音實(shí)現(xiàn) //========================demo.cs====================== using System; using System.Windows.Forms; using Bedlang; //引用名稱(chēng)空間 public class demo : Form { public static void Main() { Application.Run( new demo() ); } public demo(){ Speech s = new Speech(); //創(chuàng)建一個(gè)Speech對(duì)象 s.Speak("Bedlang"); //發(fā)音 } } //========================demo.cs====================== 6.編譯demo.cs csc demo.cs /r:bedlang.dll 7.運(yùn)行demo.exe 程序發(fā)音啦.
|