SpeechRecognitionEngine.InstalledRecognizers 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回有关当前系统中安装的所有语音识别器的信息。
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 属性。