麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > C# > 正文

用C#實現(xiàn)語音朗讀技術(shù)

2023-05-14 16:26:30
字體:
供稿:網(wǎng)友

本文使用MSTTS實現(xiàn)了語音朗讀功能,非常實用,你編寫完就可以用它來幫助你朗讀引文資料啦。只要進行下面的幾個步驟就可以了。

1.安裝MSTTS   如果你有裝金山詞霸,系統(tǒng)就已經(jīng)安裝了,可以在winnt/speech中打到vtxtauto.tlb文件;

2.用.Net SDK自帶的tlbimp工具把vtxtauto.tlb轉(zhuǎn)換成.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); //發(fā)音 
                } 
        }
}
//========================Speech.cs======================

4.編譯Bedlang.Speech 

csc /target:library /out:Bedlang.dll speech.cs /r:mstts.dll

如果用vs.net開發(fā),可直接生成項目就可以了。

5.發(fā)音實現(xiàn) 

分別加入Label,TextBox,Button控件各一個到windows Form中,修改它們的屬性,源代碼如下:

//========================demo.cs======================

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; 
                /// 
                /// 必需的設(shè)計器變量。 
                /// 
                private System.ComponentModel.Container components = null; 
                public demo() 
                { 
                        // 
                        // Windows 窗體設(shè)計器支持所必需的 
                        // 
                        InitializeComponent(); 
                        // 
                        // TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼 
                        // 
                } 
                /// 
                /// 清理所有正在使用的資源。 
                /// 
                protected override void Dispose( bool disposing ) 
                { 
                        if( disposing ) 
                        { 
                                if (components != null) 
                                { 
                                        components.Dispose(); 
                                } 
                       } 
                        base.Dispose( disposing ); 
                } 
                #region Windows Form Designer generated code 
                /// 
                /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改 
                /// 此方法的內(nèi)容。 
                /// 
                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 = "輸入要朗讀的文字:"; 
                        // 
                        // 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 = "朗讀"; 
                        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 
                /// 
                /// 應(yīng)用程序的主入口點。 
                /// 
                [STAThread] 
                static void Main() 
                { 
                        Application.Run(new demo()); 
                } 
                private void button1_Click(object sender, System.EventArgs e) 
                { 
                        Speech s=new Speech(); //創(chuàng)建一個Speech對象 
                        if(textBox1.Text.Length==0) 
                                s.Speak("Please input letter."); //發(fā)音 
                        else 
                                s.Speak(textBox1.Text); 
                } 
        }
}
//========================demo.cs======================

6.編譯demo.cs 

csc demo.cs /r:bedlang.dll

也可以在在Visual Studio.net集成開發(fā)環(huán)境中直接編譯。

7.運行demo.exe

輸入要要朗讀的文字,看看是否能正確讀出來。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 亚洲国产精品一区二区三区 | 在线视频1区| 日韩欧美电影一区二区三区 | 黄视频网址 | 久久久一区二区三区四区 | 国产精品视频一区二区三区四区五区 | 12av毛片 | 91成人在线网站 | 亚洲九色 | 精品在线观看一区二区 | 国产精品视频一区二区三区四区国 | 欧美h版在线观看 | 久草在线视频在线 | 九九热精品免费 | 久在线观看福利视频69 | 日本最新免费二区三区 | 免费1级做55爰片l在线观看 | 粉嫩粉嫩一区二区三区在线播放 | 中文字幕在线观看免费 | 一级做a爰片性色毛片2021 | 看黄在线| 在火车上摸两乳爽的大叫 | 午夜视频福利 | 欧美国产综合视频 | 亚洲日韩中文字幕一区 | 久久亚洲国产午夜精品理论片 | 久久久电影电视剧免费看 | 久久精品一级片 | 成人做爰高潮片免费视频韩国 | 最污网站 | 看国产一级毛片 | 中文字幕在线观看www | 黄在线观看在线播放720p | 爽爽淫人网 | 成年人性视频 | 一级国产精品一级国产精品片 | 黄色毛片免费看 | 久久人人av | 欧美城网站地址 | av电影在线网站 | 日韩黄在线观看 |