SpeechRecognizer.Grammars Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a collection of the Grammar objects that are loaded in this SpeechRecognizer instance.
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)
A collection of the Grammar objects that the application loaded into the current instance of the shared recognizer.
The following example outputs information to the console for each speech recognition grammar loaded into the shared speech recognizer.
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.");
}
}
}
This property does not return any speech recognition grammars loaded by another application.
Продукт | Версии |
---|---|
.NET | 8 (package-provided), 9 (package-provided), 10 (package-provided) |
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
Обратна връзка за .NET
.NET е проект с отворен код. Изберете връзка, за да предоставите обратна връзка: