1.前言:
在許多的工廠應用中,常需要使用文字轉語音的方式提醒操作人員或是工程師了解目前生產狀況,警報或是即時訊息的通知,利用微軟提供的Speech API,可以很輕鬆完成此項程式開發應用。

2.說明:
有關Microsoft Speech API的說明請參考MSDN:
http://msdn.microsoft.com/en-us/library/ee125663(v=vs.85).aspx

加入參考
在COM元件中選擇Microsoft Speech Object Library 5.4

加入命名空間:

using SpeechLib;

應用一:

private void Form1_Load(object sender, EventArgs e)
{
	SpVoiceClass voice = new SpVoiceClass();
	voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(1);//Item(1)男聲
	voice.Speak("You got e-mail", SpeechVoiceSpeakFlags.SVSFlagsAsync);//SVSFlagsAsync: Specifies that the Speak call should be asynchronous. That is, it will return immediately after the speak request is queued.
}

應用二:

private void button1_Click(object sender, EventArgs e)
{
	SpVoiceClass voice = new SpVoiceClass();
	voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(2);//Item(2)女聲
	voice.Speak("Welcome to text to speech system.", SpeechVoiceSpeakFlags.SVSFDefault);//SVSFDefault: Specifies that the default settings

	System.Threading.Thread.Sleep(3000);
	voice.Speak("Warning, SPC chart is out of upper control limit!", SpeechVoiceSpeakFlags.SVSFDefault);

	System.Threading.Thread.Sleep(3000);
	voice.Speak("Alarm, SPC chart is out of upper spec limit!", SpeechVoiceSpeakFlags.SVSFDefault);
}

應用三:

private void button2_Click(object sender, EventArgs e)
{
	SpVoiceClass voice = new SpVoiceClass();
	voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);//Item(0)中文女聲
	voice.Speak("歡迎來到文字轉語音系統", SpeechVoiceSpeakFlags.SVSFDefault);

	System.Threading.Thread.Sleep(3000);
	voice.Speak("注意,SPC超過警戒值上限", SpeechVoiceSpeakFlags.SVSFDefault);

	System.Threading.Thread.Sleep(3000);
	voice.Speak("警告,SPC超過規格上限", SpeechVoiceSpeakFlags.SVSFDefault);
}
arrow
arrow
    創作者介紹
    創作者 西夏普 的頭像
    西夏普

    西夏普的部落格

    西夏普 發表在 痞客邦 留言(0) 人氣()