SpeechRecognitionEngine.InstalledRecognizers returns No recognizer installed - c#

I am trying to get a simple speech recognition program started but it does not work, I've installed some languages (en-GB & en-US) but whenever I use the following:
SpeechRecognitionEngine.InstalledRecognizers
it returns an empty collection. Even when I just try to start a recognizer it will return "no recognizer installed". But when I reinstall a language, it says that it is already installed.
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();
}
}
For what reason is it unable to find the installed recognizers?
Edit:
This is the exception: {System.ArgumentException: No recognizer of the required ID found.
Parameter name: culture
at System.Speech.Recognition.SpeechRecognitionEngine..ctor(CultureInfo culture)
and: var recognizers = SpeechRecognitionEngine.InstalledRecognizers(); returns a collection with a count of 0

The problem was that I installed language packs that can be accessed by Microsoft.Speech and I was using System.Speech, when I switched to Microsoft.Speech it worked.

Related

Microsoft Speech Recognition setInputToDefaultAudioDevice throws exception

hello guys I'm in trouble in MS Speech recognition.
my code is simple.
static void init()
{
string enUsEngine = string.Empty;
foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
{
Console.WriteLine(ri.Culture);
if (ri.Culture.Name.Equals("en-US") == true)
{
enUsEngine = ri.Id;
}
}
SpeechRecognitionEngine recogEngine = new SpeechRecognitionEngine(enUsEngine);
Grammar grammar = new Grammar("grammar.xml");
recogEngine.LoadGrammar(grammar);
recogEngine.SpeechRecognized += recogEngine_SpeechRecognized;
recogEngine.RecognizeCompleted += recogEngine_RecognizeCompleted;
recogEngine.SetInputToDefaultAudioDevice();
recogEngine.RecognizeAsync(RecognizeMode.Multiple);
}
and then throws InvalidOperationException in call
(System.InvalidOperationException: Cannot find the requested data
item, such as a data key or value.)
SetInputToDefaultAudioDevice(); method
I downloaded MSSpeech sdk and installed it (Microsoft.speech.dll).
also downloaded language packs. (en-us, ko-kr)
and also My microphone driver installed and enabled in control panel.
please help me.
My operating system is Windows 10 is that a problem for using Speech Recognition api?
Most probably you are using Microsoft.Speech.Recognition and you reall should be using System.Speech.Recognition.
Change this:
using Microsoft.Speech.Recognition;
to this:
using System.Speech.Recognition;
You can leave the rest of the code as it is.
Wh? Well here are some answers:
What is the difference between System.Speech.Recognition and Microsoft.Speech.Recognition?
In short Microsoft.Speech.Recognition is for servers and works with low quality audio like you find in call centres (used for automation etc.), this means it is not compatible with all audio input devices.
On contrary System.Speech.Recognition is for Desktop apps and it fully supports default recording devices installed on Windows.

Error "No recognizer is installed" with recognition speech [duplicate]

This question already has an answer here:
SpeechRecognitionEngine.InstalledRecognizers returns No recognizer installed
(1 answer)
Closed 8 years ago.
I tried to recognition speech in C# but it began bad. I had followed some tutorials in YouTube but this error appear every time. So I got the Microsoft MSDN code and I tried to find some solutions in Google. This is the code I'm using:
public Form1()
{
InitializeComponent();
Initialize();
}
private void Initialize()
{
// Create a new SpeechRecognitionEngine instance.
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
// Configure the input to the recognizer.
//sre.SetInputToWaveFile(#"c:\Test\Colors.wav");
sre.SetInputToDefaultAudioDevice();
// Create a simple grammar that recognizes "red", "green", or "blue".
Choices colors = new Choices();
colors.Add(new string[] { "red", "green", "blue" });
// Create a GrammarBuilder object and append the Choices object.
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
// Create the Grammar instance and load it into the speech recognition engine.
Grammar g = new Grammar(gb);
sre.LoadGrammar(g);
// Register a handler for the SpeechRecognized event.
sre.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
// Start recognition.
sre.Recognize();
}
// Create a simple handler for the SpeechRecognized event.
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
MessageBox.Show("Speech recognized: " + e.Result.Text);
}
I already downloaded the Microsoft Speech Platform SDK and the Runtime Languages (US). The error persists.
I also already had used this code, as I saw in a topic here in StackOverflow:
sre = new SpeechRecognitionEngine(new CultureInfo("en-GB"));
It didn't work, so I tried to use this (as I saw in MSDN):
SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
When I tried to use those codes, the error change and say: "No recognizer of the required ID found".
I use the Windows 7 (Home Basic, x64), Microsoft Visual C# 2010 Express. My default language (the system language also is) is Portuguese (Brazil), maybe it's the error cause?
Well, thats it, I hope I wrote all detailed for you understand. Sorry for my english I'm training this, haha :P
Run the following to determine what recognizers you have installed, breakpoint / debug and inspect if you need to
foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
{
System.Diagnostics.Debug.WriteLine(ri.Culture.Name);
}
And use one of the listed cultures in the SpeechRecognitionEngine constructor

Speech Recognition is not available on this system. SAPI and Speech Recognition engines cannot be found

Good day!
I try to write simple speech to text engine use Speech SDK 11.
So try to execute test from this example .
So , i just create console app and run code. (with task)
Task speechRecognizer = new Task(DoWork);
speechRecognizer.Start();
speechRecognizer.Wait();
static void DoWork()
{
// Create a new SpeechRecognitionEngine instance.
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
// Configure the input to the recognizer.
sre.SetInputToWaveFile(#"c:\Test\Colors.wav");
// Create a simple grammar that recognizes "red", "green", or "blue".
Choices colors = new Choices();
colors.Add(new string[] { "red", "green", "blue" });
// Create a GrammarBuilder object and append the Choices object.
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
// Create the Grammar instance and load it into the speech recognition engine.
Grammar g = new Grammar(gb);
sre.LoadGrammar(g);
// Register a handler for the SpeechRecognized event.
sre.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
// Start recognition.
sre.Recognize();
}
But i get this exception:Speech Recognition is not available on this system. SAPI and Speech Recognition engines cannot be found.I try to install SpeechSDK51 ,but have no result.
Can you tell me how to fix this error?
Thank you!
P.S. Error arises at :
// Create a new SpeechRecognitionEngine instance.
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
Did you add both the x64 and the x86 versions of the runtime component? It worked for me.
Faced the same issue. The runtime wasn't installed. Installing the runtime from microsoft official download page resolved my issue.

Program does not load if Speech Recognition Language is set to anything other than English - US

I have added a speech recognition feature to my program. However, if I try to run the program and the language in the Speech Properties is set to anything other than "Microsoft Speech Recognizer 8.0 for Windows (English - US), the program fails to load.
I would like to have it so that the program will load no matter which language is selected.
The code for my voice command is as follows:
vcstat.Text = "Voice Control Enabled";
recognizer = new SpeechRecognizer();
recognizer.SpeechDetected += recognizer_SpeechDetected;
recognizer.SpeechRecognitionRejected += recognizer_SpeechRecognitionRejected;
recognizer.SpeechRecognized += recognizer_SpeechRecognized;
GrammarBuilder grammar = new GrammarBuilder();
grammar.Append(new Choices("Cut", "Copy", "Paste", "Select All Text", "Print", "Unselect All Text", "Delete", "Save", "Save As", "Open", "New", "Close Basic Word Processor"));
recognizer.LoadGrammar(new Grammar(grammar));
There is some more code, but that's to do with the actual commands, so I don't think it's necessary to post it here.
If somebody could help me figure out a way to allow the program to start, regardless of the Speech Recognition Engine in use, I'd really appreciate it.
You can only use Speech Recognition in a different language if a MUI language pack is installed on the client's computer for one of the supported languages.
http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/windows-7-speech-recognition-language-selection/0a859099-a76d-4799-abe9-847997399927

C# Speech recognition error - The language for the grammar does not match the language of the speech recognizer

I have problem with my speech recognition.
It works on "English" windows with no problem.
It also works on some "Foreign" windows too. But only some.
I'm getting that exception:
The language for the grammar does not match the language of the speech recognizer
I added my own words to dictionary.
How can I fix it?
Not sure which version .net you are on, but I'll attempt to answer.
On your English Windows version, please navigate to C:\Program Files\Reference Assemblies\Microsoft\Framework[YOUR .NET VERSION]
You should find System.Speech.dll,
Make sure to bring this .dll over to your foreign computer, and everything should run smoothly.
I had the same problem on my friends Computer. So I made this (it is just part of the code, because all the code is really long ):
...
RecognizerInfo recognizerInfo = null;
foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
{
if ((ri.Culture.TwoLetterISOLanguageName.Equals("en")) && (recognizerInfo == null))
{
recognizerInfo = ri;
break;
}
}
SpeechRecognitionEngine SpeachRecognition = new SpeechRecognitionEngine(recognizerInfo);
GrammarBuilder gb = new GrammarBuilder(startLiserninFraze);
gb.Culture = recognizerInfo.Culture;
grammar = new Grammar(gb);
SpeachRecognition.RequestRecognizerUpdate();
SpeachRecognition.LoadGrammar(grammar);
SpeachRecognition.SpeechRecognized += SpeachRecognition_SpeechRecognized;
SpeachRecognition.SetInputToDefaultAudioDevice();
SpeachRecognition.RecognizeAsync(RecognizeMode.Multiple);
...
So this should work. My friends PC supported 2 instances of "en" or in "eng". Not sure why. So the code selects first one. I found some pieces of code on the internet and some of this is made by me.
SpeachRecognition.SpeechRecognized += SpeachRecognition_SpeechRecognized;
is made to make an event when everything is recognized. just type:
SpeachRecognition.SpeechRecognized +=
and the press TAB button (atleast in VS 2013) few times. and then in the bottom of code it will generate something like this:
void SpeachRecognition_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
//then will be some line that you need to replace with your code
}
I hope this will help. :)

Categories

Resources