"Computer reading" (English) a good trigger point, through which can achieve the electronic novel reading, English listening test, English word learning ...
The following speech has a simple encapsulation of the Mstts.
1. Install good Mstts (if you have to install PowerWord, the system has been installed), you can hit the Winnt\speech in the Vtxtauto.tlb file;
2. Convert Vtxtauto.tlb to a. dll format with the TlbImp tool with the. Net SDK:
TlbImp Vtxtauto.tlb/silent/namespace:mstts/out:mstts.dll
The Mstts.dll has become a class of the. NET Framework runtime.
3. Write a simple class that encapsulates the 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. Compile Bedlang.speech
Csc/target:library/out:bedlang.dll Speech.cs/r:mstts.dll
If you use vs.net development, you can directly build the project on it.
5. Pronunciation Realization
========================demo.cs======================
Add the Label,textbox,button control individually to the Windows Form, modify their properties, and the source code is as follows:
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Namespace Bedlang
{
///
Summary description of the Form1.
///
public class Demo:System.Windows.Forms.Form
{
Private System.Windows.Forms.Label Label1;
Private System.Windows.Forms.TextBox TextBox1;
Private System.Windows.Forms.Button button1;
///
The required designer variable.
///
Private System.ComponentModel.Container components = null;
Public demo ()
{
//
Required for Windows Forms Designer support
//
InitializeComponent ();
//
TODO: Add any constructor code after the InitializeComponent call
//
}
///
Clean up all resources that are in use.
///
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}
#region Windows Form Designer generated code
///
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
///
private void InitializeComponent ()
{
This.label1 = new System.Windows.Forms.Label ();
This.textbox1 = new System.Windows.Forms.TextBox ();
This.button1 = new System.Windows.Forms.Button ();
This. SuspendLayout ();
//
Label1
//
This.label1.Location = new System.Drawing.Point (24, 16);
This.label1.Name = "Label1";
This.label1.Size = new System.Drawing.Size (120, 23);
This.label1.TabIndex = 0;
This.label1.Text = "Enter the text to be read aloud:";
//
TextBox1
//
This.textBox1.Location = new System.Drawing.Point (24, 48);
This.textBox1.Name = "TextBox1";
This.textBox1.Size = new System.Drawing.Size (248, 21);
This.textBox1.TabIndex = 1;
This.textBox1.Text = "";
//
Button1
//
This.button1.Location = new System.Drawing.Point (112, 112);
This.button1.Name = "Button1";
This.button1.TabIndex = 2;
This.button1.Text = "read aloud";
This.button1.Click + = new System.EventHandler (This.button1_click);
//
Demo
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (292, 197);
This. Controls.AddRange (new system.windows.forms.control[] {
This.button1,
This.textbox1,
This.label1});
This. Name = "Demo";
This. Text = "Demo";
This. ResumeLayout (FALSE);
}
#endregion
///
The main entry point for the application.
///
[STAThread]
static void Main ()
{
Application.Run (New demo ());
}
private void Button1_Click (object sender, System.EventArgs e)
{
Speech s=new Speech ();//Create a Speech object
if (textbox1.text.length==0)
S.speak ("Please input letter.") );//pronunciation
Else
S.speak (TextBox1.Text);
}
}
}
========================demo.cs======================
6. Compile Demo.cs
CSC Demo.cs/r:bedlang.dll
Vs.net environment can be directly compiled into EXE files.
7. Run Demo.exe
Enter the text you want to read aloud, and the program will read aloud.