2010-10-08 17 views
2

我是C#的新手,我是Speech.Recognition的新手。 我搜索了很長時間的教程,但沒有發現那麼多,我甚至都不確定我是否正確地包含了所有內容。C#和Microsoft Speech.Recognition and Speech.Synthesis

我下載:

我編程的地方,我使用Windows XP,.NET Framework 3.5的。

現在我只想開始使用一些簡單的代碼行,比如說「hello world」或者說一個或兩個單詞作爲輸入。

我嘗試以下,當然這是行不通的:> 錯誤:

"The Typ- or Namespacename "SpeechSynthesizer" couldn't be found (Is a Using-Direktive or a Assemblyverweis missing?)"

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Speech.Recognition; 
using System.Speech.Synthesis; 

namespace System.Speech.Recognition { } 
namespace System.Speech.AudioFormat {} 
namespace System.Speech.Recognition.SrgsGrammar{} 
namespace System.Speech.Synthesis { } 
namespace System.Speech.Synthesis.TtsEngine { } 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      SpeechSynthesizer foo = new SpeechSynthesizer(); 
      foo.Speak("Test"); 
     } 
    } 
} 

編輯:

你好, 我想你的代碼,但 使用SpeechLib; 找不到:>

現在好了,我寫道:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Speech.Recognition; 
using System.Speech.Synthesis; 
using System.SpeechLib; 

namespace System.SpeechLib { } 
namespace System.Speech.Recognition { } 
namespace System.Speech.AudioFormat {} 
namespace System.Speech.Recognition.SrgsGrammar{} 
namespace System.Speech.Synthesis { } 
namespace System.Speech.Synthesis.TtsEngine { } 

,但我得到一個錯誤有:

numericUpDown1,SpVoice,SpeechVoiceSpeakFlags,textBox1 and Timeout

回答

3

Project +添加引用,.NET選項卡,選擇「System.Speech」。

項目模板預先選擇了幾個.NET程序集。但只有常見的,如System.dll,System.Core.dll等。你必須自己添加「不尋常」的。

+1

+1。 'Using'只是創建名稱空間的快捷方式。要使用它們,您需要將組件鏈接到項目。 – Mike 2010-10-08 12:22:31

+0

謝謝,我把system.speech,現在它的工作! greate - (你知道我是如何切換到德語的嗎?) – Tyzak 2010-10-08 12:28:08

+0

是的,在高中三年的德語幫助。但我不認爲你會在Windows機器上得到它,除非Windows版本是德語。不知道需要什麼,錢毫無疑問。在superuser.com上開始另一個問題 – 2010-10-08 12:44:38

0

你可以試試這個:

得到Interop.SpeechLib.dll

using SpeechLib; 

private void ReadText(string readText) 
     { 
      int iCounter = 0; 
      while (Convert.ToInt32(numericUpDown1.Value) > iCounter) 
      { 
       SpVoice spVoice = new SpVoice(); 
       spVoice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak); 
       spVoice.WaitUntilDone(Timeout.Infinite); 
       iCounter = iCounter + 1; 
      } 
     }