·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> DotNet语音技术实现

DotNet语音技术实现

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23

语音实现

    “电脑发音”(英文)一个很好的触发点,通过它可以实现电子小说阅读、英文听力测试、英文单词学习...
    下面的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
  程序发音啦.