Voice technology with C #

xiaoxiao2021-03-20  232

"Computer Read" (English) A good trigger point, through it can achieve electronic novel reading, English listening test, English word learning ... The following SPEECH has made MSTTS simple packages. 1. Install MSTTS (if you have a Minshan word tyrant, the system is already installed), you can play vtxtauto.tlb files in WinNT / Speech; 2. Convert vtxtAuto.tlb to the TLBIMP tool with .NET SDK .dll format: tlbimp vtxtauto.tlb / silent / namespace: MSTTS /OUT: MSTTS.DLL This time MSTTS.DLL This time the MSTTS.dll has become a class of the .NET Framework running library. 3. Write an simple class of a package VTXTAUTO: Speech.

/ /======================================================= = using System; using mstts; // MSTTS namespace namespace Bedlang {// definition of namespace public class Speech {private VTxtAuto VTxtAutoEx; public Speech () {VTxtAutoEx = new VTxtAuto (); VTxtAutoEx.Register ( "", "") ; // Register the COM component} 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 develop by vs.net, you can generate a project directly. 5. Pronunciation implementation

/ /================================================== were added = Label, TextBox, Button to a respective control windows Form, modify their properties, 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 {/// /// Form1 summary description. /// 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; /// // / Essential designer variables. /// private system.componentmodel.container components = null; public demo () {//// ' Function code //} / / / / / Clean all the resources being used. /// Protected Override Void Dispose (DISPOSIING) {if (component! = null) {Components.dispose ();}} Base.Dispose ();} # Region Windows Form Designer generated code // / /// Designer Support the required method - Do not use the code editor to modify the // / 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 you want 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"; 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 Syst Em.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."); // Elses.Speak (TextBox1.text);}}} // ========== ============== Demo.cs =============================== 6. Compile DEMO.CS CSC DEMO.CS / R: Bedlang.dll vs.net environment can be directly compiled into an EXE file. 7. Run Demo.exe Enter the text you want to read, the program can read it.

转载请注明原文地址:https://www.9cbs.com/read-130397.html

New Post(0)