共用方式為


SpeechRecognitionEngine.InstalledRecognizers 方法

定義

傳回目前的系統上所有已安裝的語音辨識器的資訊。

public:
 static System::Collections::ObjectModel::ReadOnlyCollection<System::Speech::Recognition::RecognizerInfo ^> ^ InstalledRecognizers();
public static System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Recognition.RecognizerInfo> InstalledRecognizers ();
static member InstalledRecognizers : unit -> System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Recognition.RecognizerInfo>
Public Shared Function InstalledRecognizers () As ReadOnlyCollection(Of RecognizerInfo)

傳回

RecognizerInfo 物件的唯讀集合,這些物件會描述已安裝的辨識器。

範例

下列範例示範示範基本語音辨識的主控台應用程式的一部分。 此範例會使用 方法所 InstalledRecognizers 傳回的集合來尋找支援英文的語音辨識器。

using System;  
using System.Speech.Recognition;  

namespace SpeechRecognitionApp  
{  
  class Program  
  {  
    static void Main(string[] args)  
    {  

      // Select a speech recognizer that supports English.  
      RecognizerInfo info = null;  
      foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())  
      {  
        if (ri.Culture.TwoLetterISOLanguageName.Equals("en"))  
        {  
          info = ri;  
          break;  
        }  
      }  
      if (info == null) return;  

      // Create the selected recognizer.  
      using (SpeechRecognitionEngine recognizer =  
        new SpeechRecognitionEngine(info))  
      {  

        // Create and load a dictation grammar.  
        recognizer.LoadGrammar(new DictationGrammar());  

        // Add a handler for the speech recognized event.  
        recognizer.SpeechRecognized +=   
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  

        // Configure input to the speech recognizer.  
        recognizer.SetInputToDefaultAudioDevice();  

        // Start asynchronous, continuous speech recognition.  
        recognizer.RecognizeAsync(RecognizeMode.Multiple);  

        // Keep the console window open.  
        while (true)  
        {  
          Console.ReadLine();  
        }  
      }  
    }  

    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("Recognized text: " + e.Result.Text);  
    }  
  }  
}  

備註

若要取得目前辨識器的相關資訊,請使用 RecognizerInfo 屬性。

適用於

另請參閱