共用方式為


SpeechRecognizer.Grammars 屬性

定義

取得在這個 Grammar 執行個體中載入之 SpeechRecognizer 物件的集合。

public:
 property System::Collections::ObjectModel::ReadOnlyCollection<System::Speech::Recognition::Grammar ^> ^ Grammars { System::Collections::ObjectModel::ReadOnlyCollection<System::Speech::Recognition::Grammar ^> ^ get(); };
public System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Recognition.Grammar> Grammars { get; }
member this.Grammars : System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Recognition.Grammar>
Public ReadOnly Property Grammars As ReadOnlyCollection(Of Grammar)

屬性值

Grammar物件的集合,應用程式會將這些物件載入共用的辨識器的目前執行個體中。

範例

下列範例會針對載入共用語音辨識器的每個語音辨識文法,將資訊輸出至主控台。

using System;  
using System.Collections.Generic;  
using System.Speech.Recognition;  
using System.Threading;  

namespace SharedRecognizer  
{  
  class Program  
  {  
    static void Main(string[] args)  
    {  
      using (SpeechRecognizer recognizer = new SpeechRecognizer())  
      {  
        Grammar sampleGrammar = new Grammar(new GrammarBuilder("sample phrase"));  
        sampleGrammar.Name = "Sample Grammar";  
        recognizer.LoadGrammar(sampleGrammar);  

        OutputGrammarList(recognizer);  
      }  

      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  

    private static void OutputGrammarList(SpeechRecognizer recognizer)  
    {  
      List<Grammar> grammars = new List<Grammar>(recognizer.Grammars);  
      if (grammars.Count > 0)  
      {  
        Console.WriteLine("Loaded grammars:");  
        foreach (Grammar g in grammars)  
        {  
          Console.WriteLine("  Grammar: {0}",  
            (g.Name != null) ? g.Name : "<no name>");  
        }  
      }  
      else  
      {  
        Console.WriteLine("No grammars loaded.");  
      }  
    }  
}  

備註

此屬性不會傳回另一個應用程式載入的任何語音辨識文法。

適用於

另請參閱