c#之語音功能的實現



代碼示例:

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文件),還是不能解決,至於其他辦法暫時還沒找到。。。。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章