代碼示例:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SpeechLib;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 按下發音按鈕之後,對文本中的內容執行語音功能
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice Voice = new SpVoice();
Voice.Speak(textBox1.Text, SpFlags);
}
}
}
注意:
實現該功能是還需要引用com組件
Microsoft speech objec libray 的路徑如下
因爲有個別電腦上沒有該文件,所以不能添加引用,但是在其他電腦上將Speech整個文件拷到電腦上去(附上speech文件),還是不能解決,至於其他辦法暫時還沒找到。。。。