DotNet语音技术实现(实现电脑发音)
??? 下面的Speech已對MSTTS作了簡單封裝。
1.安裝好MSTTS,可以在windows\speech中打到vtxtauto.lib文件
2.用.Net SDK自帶的tlbimp工具把vtxtauto.tlb轉換成.dll格式:
? tlbimp vtxtauto.tlb /silent /namespace:mstts /out:mstts.dll
? 這時的mstts.dll已成為.net framework運行庫的一個類。
3.編寫一個封裝vtxtauto的簡單類:Speech .
//========================Speech.cs======================
using System;
using mstts;? //MSTTS名稱空間
namespace Bedlang{????? //定義名稱空間
public class Speech{
? private VTxtAuto VTxtAutoEx;
? public Speech(){
?? VTxtAutoEx = new VTxtAuto();?
?? VTxtAutoEx.Register(" "," "); //注冊COM組件??
? }
? public void Speak(String text){
?? VTxtAutoEx.Speak(text, 0);?? //發音
? }
}
}
//========================Speech.cs======================
4.編譯Bedlang.Speech
? csc /target:library /out:Bedlang.dll? speech.cs /r:mstts.dll
5.發音實現
//========================demo.cs======================
using System;
using System.Windows.Forms;
using Bedlang;?? //引用名稱空間
public class demo : Form {?????
public static void Main() {
? Application.Run( new demo() );
}
?
public demo(){
? Speech s = new Speech();??? //創建一個Speech對象
? s.Speak("Bedlang");???? //發音?
}
}
//========================demo.cs======================
6.編譯demo.cs
? csc demo.cs /r:bedlang.dll
7.運行demo.exe
? 程序發音啦.
總結
以上是生活随笔為你收集整理的DotNet语音技术实现(实现电脑发音)的全部內容,希望文章能夠幫你解決所遇到的問題。