SpeechRecognitionEngine Constructors
Definition
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.
Initializes a new instance of the SpeechRecognitionEngine class.
Overloads
SpeechRecognitionEngine() |
Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for the system. |
SpeechRecognitionEngine(CultureInfo) |
Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for a specified locale. |
SpeechRecognitionEngine(RecognizerInfo) |
Initializes a new instance of the SpeechRecognitionEngine using the information in a RecognizerInfo object to specify the recognizer to use. |
SpeechRecognitionEngine(String) |
Initializes a new instance of the SpeechRecognitionEngine class with a string parameter that specifies the name of the recognizer to use. |
Remarks
You can construct a SpeechRecognitionEngine instance from any of the following:
The default speech recognition engine for the system
A specific speech recognition engine that you specify by name
The default speech recognition engine for a locale that you specify
A specific recognition engine that meets the criteria that you specify in a RecognizerInfo object.
Before the speech recognizer can begin recognition, you must load at least one speech recognition grammar and configure the input for the recognizer.
To load a grammar, call the LoadGrammar or LoadGrammarAsync method.
To configure the audio input, use one of the following methods:
SpeechRecognitionEngine()
- Source:
- SpeechRecognitionEngine.cs
- Source:
- SpeechRecognitionEngine.cs
- Source:
- SpeechRecognitionEngine.cs
Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for the system.
public:
SpeechRecognitionEngine();
public SpeechRecognitionEngine ();
Public Sub New ()
Remarks
Before the speech recognizer can begin speech recognition, you must load at least one recognition grammar and configure the input for the recognizer.
To load a grammar, call the LoadGrammar or LoadGrammarAsync method.
To configure the audio input, use one of the following methods:
Applies to
SpeechRecognitionEngine(CultureInfo)
- Source:
- SpeechRecognitionEngine.cs
- Source:
- SpeechRecognitionEngine.cs
- Source:
- SpeechRecognitionEngine.cs
Initializes a new instance of the SpeechRecognitionEngine class using the default speech recognizer for a specified locale.
public:
SpeechRecognitionEngine(System::Globalization::CultureInfo ^ culture);
public SpeechRecognitionEngine (System.Globalization.CultureInfo culture);
new System.Speech.Recognition.SpeechRecognitionEngine : System.Globalization.CultureInfo -> System.Speech.Recognition.SpeechRecognitionEngine
Public Sub New (culture As CultureInfo)
Parameters
- culture
- CultureInfo
The locale that the speech recognizer must support.
Exceptions
None of the installed speech recognizers support the specified locale, or culture
is the invariant culture.
Culture
is null
.
Examples
The following example shows part of a console application that demonstrates basic speech recognition, and initializes a speech recognizer for the en-US locale.
using System;
using System.Speech.Recognition;
namespace SpeechRecognitionApp
{
class Program
{
static void Main(string[] args)
{
// Create an in-process speech recognizer for the en-US locale.
using (
SpeechRecognitionEngine recognizer =
new SpeechRecognitionEngine(
new System.Globalization.CultureInfo("en-US")))
{
// 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);
}
}
}
Remarks
Microsoft Windows and the System.Speech API accept all valid language-country codes. To perform speech recognition using the language specified in the CultureInfo
argument, a speech recognition engine that supports that language-country code must be installed. The speech recognition engines that shipped with Microsoft Windows 7 work with the following language-country codes.
en-GB. English (United Kingdom)
en-US. English (United States)
de-DE. German (Germany)
es-ES. Spanish (Spain)
fr-FR. French (France)
ja-JP. Japanese (Japan)
zh-CN. Chinese (China)
zh-TW. Chinese (Taiwan)
Two-letter language codes such as "en", "fr", or "es" are also permitted.
Before the speech recognizer can begin recognition, you must load at least one speech recognition grammar and configure the input for the recognizer.
To load a grammar, call the LoadGrammar or LoadGrammarAsync method.
To configure the audio input, use one of the following methods:
Applies to
SpeechRecognitionEngine(RecognizerInfo)
- Source:
- SpeechRecognitionEngine.cs
- Source:
- SpeechRecognitionEngine.cs
- Source:
- SpeechRecognitionEngine.cs
Initializes a new instance of the SpeechRecognitionEngine using the information in a RecognizerInfo object to specify the recognizer to use.
public:
SpeechRecognitionEngine(System::Speech::Recognition::RecognizerInfo ^ recognizerInfo);
public SpeechRecognitionEngine (System.Speech.Recognition.RecognizerInfo recognizerInfo);
new System.Speech.Recognition.SpeechRecognitionEngine : System.Speech.Recognition.RecognizerInfo -> System.Speech.Recognition.SpeechRecognitionEngine
Public Sub New (recognizerInfo As RecognizerInfo)
Parameters
- recognizerInfo
- RecognizerInfo
The information for the specific speech recognizer.
Examples
The following example shows part of a console application that demonstrates basic speech recognition, and initializes a speech recognizer that supports the English language.
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);
}
}
}
Remarks
You can create an instance of this class for any of the installed speech recognizers. To get information about which recognizers are installed, use the InstalledRecognizers method.
Before the speech recognizer can begin recognition, you must load at least one speech recognition grammar and configure the input for the recognizer.
To load a grammar, call the LoadGrammar or LoadGrammarAsync method.
To configure the audio input, use one of the following methods:
Applies to
SpeechRecognitionEngine(String)
- Source:
- SpeechRecognitionEngine.cs
- Source:
- SpeechRecognitionEngine.cs
- Source:
- SpeechRecognitionEngine.cs
Initializes a new instance of the SpeechRecognitionEngine class with a string parameter that specifies the name of the recognizer to use.
public:
SpeechRecognitionEngine(System::String ^ recognizerId);
public SpeechRecognitionEngine (string recognizerId);
new System.Speech.Recognition.SpeechRecognitionEngine : string -> System.Speech.Recognition.SpeechRecognitionEngine
Public Sub New (recognizerId As String)
Parameters
- recognizerId
- String
The token name of the speech recognizer to use.
Exceptions
No speech recognizer with that token name is installed, or recognizerId
is the empty string ("").
recognizerId
is null
.
Examples
The following example shows part of a console application that demonstrates basic speech recognition, and creates an instance of the Speech Recognizer 8.0 for Windows (English - US).
using System;
using System.Speech.Recognition;
namespace SpeechRecognitionApp
{
class Program
{
static void Main(string[] args)
{
// Create an instance of the Microsoft Speech Recognizer 8.0 for
// Windows (English - US).
using (SpeechRecognitionEngine recognizer =
new SpeechRecognitionEngine("MS-1033-80-DESK"))
{
// Create and load a dictation grammar.
recognizer.LoadGrammar(new DictationGrammar());
// Add a handler for the speech recognized event.
recognizer.SpeechRecognized += new EventHandler(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);
}
}
}
Remarks
The token name of the recognizer is the value of the Id property of the RecognizerInfo object returned by the RecognizerInfo property of the recognizer. To get a collection of all the installed recognizers, use the static InstalledRecognizers method.
Before the speech recognizer can begin recognition, you must load at least one speech recognition grammar and configure the input for the recognizer.
To load a grammar, call the LoadGrammar or LoadGrammarAsync method.
To configure the audio input, use one of the following methods: