2013-08-20 63 views
1

我在C#應用程序中成功使用.NET語音識別部分進行基本的說話。在使用語音識別時記錄音頻數據?

除此之外,是否可以記錄它在我的應用程序中拾取的音頻,並與我的應用程序識別它。我想保存一段時間以便日後分析。

您是否會創建一個單獨的線程,然後在對麥克風說話時將一些.NET音頻記錄放在那裏?我只想將它們保存在本地目錄中,格式爲.wav。一個簡單的記錄,如48khz和16位樣本。

我正在使用一個正常形式的應用程序,這是我現在只是給你一個想法的語音代碼的類型。

using System.Speech.Recognition; 

//then inside the class and namespace I have 
    public partial class Form1 : Form 
    { 
     SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine(); 


//declared variables here 
//now I initialize 

     public Form1() 
     { 
      InitializeComponent(); 
      _recognizer.SetInputToDefaultAudioDevice(); 
      _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"Commands.txt"))))); 
      _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized); 
      _recognizer.RecognizeAsync(RecognizeMode.Multiple); 
      systemOnline(); 
     } 

void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) 
     { 
      string time = now.GetDateTimeFormats('t')[0]; 
      int ranNum; 
      string speech = e.Result.Text; 
      switch (speech) 
      { 

       //Open Google 
       case "Google": 
       //code opens google in default browser 
+1

它看起來好像已經將它保存在內存中,所以你只需要將內存位置發送到文件,然後再從應用程序中釋放該記錄。我認爲。 – Malachi

回答

2

看看Windows APIs。我相信你可以在那裏註冊一個處理程序/事件處理程序/攔截器來獲取音頻數據。看看下面的鏈接:maybe helpfull

+0

你的鏈接中的第二個我會研究更多。看來我可以將它用作共享事件。謝謝:) – camdixon

+0

你會推薦把它放在一個單獨的線程中嗎? – camdixon

+0

不確定,線程不是我的優勢領域,你必須看看你的CPU和它的功能,如果它是一個多核並且支持在每個內核上多個音頻數據/流計算,那麼線程將會很有幫助! –