Computer reading "( English ) It is a good trigger point for reading electronic novels, testing English listening, and learning English words. ...
The following Speech Pair Mstts Simple encapsulation.
1. Install Mstts (If you have installed Kingsoft Mac, the system has already been installed, under c: \ windows \ speech) , You can Winntspeech Hitting Vtxtauto. TLB File; If not, you need to install TTS and SAPI to have these two files on Jinshan's disk!
Tts: Microsoft text-to-speech engine)
SAPI: Microsoft Speech API (voice API)
2. Use . Net SDK Built-in Tlbimp Tool Vtxtauto. TLB Convert . Dll Format :
Tlbimp vtxtauto. TLB/silent/namespace: mstts/out: mstts. dll
At this time Mstts. dll Already . NET Framework A class of the Runtime Library.
3. Write an encapsulation Vtxtauto Simple class : Speech.
// ====================================== Speech. CS ====================================
Using system;
Using mstts; // mstts Namespace
Namespace bedlang {// Define namespace
Public class speech {
Private vtxtauto vtxtautoex;
Public Speech (){
Vtxtautoex = new vtxtauto ();
Vtxtautoex. Register ("","");// Register Com Components
}
Public void speak (string text ){
Vtxtautoex. Speak (text, 0 );// Pronunciation
}
}
}
// ====================================== 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 generate a project.
5. Pronunciation implementation
// =================================== Demo. CS ====================================
Add Label, Textbox, button Control one Windows form , Modify their attributes,Source codeAs follows:
Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. Data;
Namespace bedlang
{
///
/// 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;
///
/// Required designer variables.
///
Private system. componentmodel. Container components = NULL;
Public demo ()
{
//
// Windows Required by the Form Designer
//
Initializecomponent ();
//
// Todo: In Initializecomponent Add Any constructor after the callCode
//
}
///
/// Clear all resources in use.
///
Protected override void dispose (bool disposing)
{
If (disposing)
{
If (components! = NULL)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}
# Region windows Form Designer generated code
///
/// Required methods supported by the designer - Do not use the code editor to modify
/// The content 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 read: ";
//
// 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. button#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
///
/// ApplicationProgram.
///
[Stathread]
Static void main ()
{
Application. Run (new demo ());
}
Private void button#click (Object sender, system. eventargs E)
{
Speech S = new speech ();// Create 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 EXE File.
7. Run Demo.exe
Enter the text to be read, and the program can read it. .
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service