日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

C#语音朗读

發布時間:2023/11/27 生活经验 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#语音朗读 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
電腦朗讀”(英文)一個很好的觸發點,通過它可以實現電子小說閱讀、英文聽力測試、英文單詞學習...
????
下面的Speech已對MSTTS作了簡單封裝。
1.
安裝好MSTTS(如果你有裝金山詞霸,系統就已經安裝了,在C:/windows/speech/下),可以在winntspeech中打到vtxtauto.tlb文件; 沒有的話,就要裝TTS和SAPI在金山的碟上有這兩個文件! ?
? ?
? TTS:Microsoft ? Text-To-Speech ? Engine ? ? (全文朗讀引擎) ?
? SAPI:Microsoft ? Speech ? API ? ? ? ? ? ? ? ? ? ? ? ? ? ? (語音API)

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
 如果用vs.net開發,可直接生成項目就可以了。
5.
發音實現
//========================demo.cs======================
分別加入Label,TextBox,Button控件各一個到windows?Form中,修改它們的屬性,源代碼如下:
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;
??///?
??///?
必需的設計器變量。
??///?
??private?System.ComponentModel.Container?components?=?null;
??public?demo()
??{
???//
???//?Windows?
窗體設計器支持所必需的
???//
???InitializeComponent();
???//
???//?TODO:?
?InitializeComponent?調用后添加任何構造函數代碼
???//
??}
??///?
??///?
清理所有正在使用的資源。
??///?
??protected?override?void?Dispose(?bool?disposing?)
??{
???if(?disposing?)
???{
????if?(components?!=?null)?
????{
?????components.Dispose();
????}
???}
???base.Dispose(?disposing?);
??}
??#region?Windows?Form?Designer?generated?code
??///?
??///?
設計器支持所需的方法?-?不要使用代碼編輯器修改
??///?
此方法的內容。
??///?
??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
??///?
??///?
應用程序的主入口點。
??///?
??[STAThread]
??static?void?Main()?
??{
???Application.Run(new?demo());
??}
??private?void?button1_Click(object?sender,?System.EventArgs?e)
??{
???Speech?s=new?Speech();??//
創建一個Speech對象
???if(textBox1.Text.Length==0)
????s.Speak("Please?input?letter.");
 //發音
???else
????s.Speak(textBox1.Text);
??}
?}
}
//========================demo.cs======================
6.
編譯demo.cs
??csc?demo.cs?/r:bedlang.dll
 Vs.net環境下可直接編譯成exe文件。
7.
運行demo.exe
??
輸入要要朗讀的文字,程序就可朗讀了啦. ?

總結

以上是生活随笔為你收集整理的C#语音朗读的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。