文字轉語音C#
- 利用WINDOWS內建文字轉語音,先檢查一下
- 或在WIN10下檢查
- 開始程式撰寫
打開喇吧
搭配語音停止_程式修正
=====================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Speech.Synthesis;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test_voice
{
public partial class WebForm1 : System.Web.UI.Page
{
//建立靜態物件
public static SpeechSynthesizer speech;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Button1.Text == "語音試聽")
{
//另外建立一個物件
speech = new SpeechSynthesizer();
//建立一個執行緒,非同步閱讀文章
new Thread(Speak).Start();
Button1.Text = "停止試聽";
}
else if (Button1.Text == "停止試聽")
{
//引用靜態物件,停止所有的閱讀
speech.SpeakAsyncCancelAll();//停止閱讀
Button1.Text = "語音試聽";
}
}
private void Speak()
{
speech.SpeakAsync(TextBox1.Text);//語音試聽方法
}
}
}
沒有留言:
張貼留言