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.dll5.发音实现
//========================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.dll7.运行demo.exe
程序发音啦.