Accuracy of MS System.Speech.Recognizer and the SpeechRecognitionEngine - c#

I am currently testing the SpeechRecognitionEngine by loading from an xml file a pretty simple rule. In fact it is a simple between ("decrypt the email", "remove encryption") or ("encrypt the email", "add encryption").
I have trained my Windows 7 PC and additionally added the words encrypt and decrypt as I realize they are very similar. The recognizer already has a problem with making a difference between these two.
The issue I am having is that it recognizes things too often. I have set the confidence to 0.93 because with my voice in a quiet room when saying the exact words sometimes only gets to 0.93. But then if I turn on the radio the voice of the announcer or a song can mean that this recognizer thinks it has heard with over 0.93 confidence with words "decrpyt the email".
Maybe Lady Gaga is backmasking Applause to secretly decrypt emails :-)
Can anyone help in working out how to do something to make this recognizer workable.
In fact the recognizer is also picking up keyboard noise as "decrypt the email". I don't understand how this is possible.
Further to my editing buddy there are at least two managed namespaces for MS Speech Microsoft.Speech and System.Speech - It is important for this question that it be know that it is System.Speech.

If the only thing the System.Speech recognizer is listening for is "encrypt the email", then the recognizer will generate lots of false positives. (Particularly in a noisy environment.) If you add a DictationGrammar (particularly a pronunciation grammar) in parallel, the DictationGrammar will pick up the noise, and you can check the (e.g.) name of the grammar in the event handler to discard the bogus recognitions.
A (subset) example:
static void Main(string[] args)
{
Choices gb = new Choices();
gb.Add("encrypt the document");
gb.Add("decrypt the document");
Grammar commands = new Grammar(gb);
commands.Name = "commands";
DictationGrammar dg = new DictationGrammar("grammar:dictation#pronunciation");
dg.Name = "Random";
using (SpeechRecognitionEngine recoEngine = new SpeechRecognitionEngine(new CultureInfo("en-US")))
{
recoEngine.SetInputToDefaultAudioDevice();
recoEngine.LoadGrammar(commands);
recoEngine.LoadGrammar(dg);
recoEngine.RecognizeCompleted += recoEngine_RecognizeCompleted;
recoEngine.RecognizeAsync();
System.Console.ReadKey(true);
recoEngine.RecognizeAsyncStop();
}
}
static void recoEngine_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)
{
if (e.Result.Grammar.Name != "Random")
{
System.Console.WriteLine(e.Result.Text);
}
}

Related

How can I handle two different languages simultaneously in a Speech-to-Text app (in C#)?

I would like to make a Speech-to-text-to-translation utility that can recognize and render both English and Spanish "on the fly." To start with, I need it to be able to process two languages (the translation piece of it I'll postpone until later).
IOW, I want it to be able to process (through the device's speaker) conversations such as:
Spanish speaker's voice captured and rendered: "Que estas haciendo?"
English speaker's voice captured and rendered: "I don't speak Spanish, or Italian, or whatever lingo that is. Speak English!"
Spanish speaker: "I asked you what you're doing."
English speaker: "Oh, not much really; I mean, none of your gol-durned business!"
(etc.)
I see here that I can set up a speech-to-text session like so:
using Microsoft.Speech.Recognition;
using Microsoft.Speech.Synthesis;
namespace ConsoleSpeech
{
class ConsoleSpeechProgram
{
static SpeechSynthesizer ss = new SpeechSynthesizer();
static SpeechRecognitionEngine sre;
static void Main(string[] args)
{
try
{
CultureInfo ci = new CultureInfo("en-us");
sre = new SpeechRecognitionEngine(ci);
sre.SetInputToDefaultAudioDevice();
sre.SpeechRecognized += sre_SpeechRecognized;
. . .
static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
string txt = e.Result.Text;
float confidence = e.Result.Confidence;
Console.WriteLine("\nRecognized: " + txt);
if (confidence < 0.60) return;
. . .
Since the CultureInfo class is instantiated with a specific language (US English shown above), I guess it would render "Que estas haciendo?" as something like "Kay is toss hossy end, oh?" and therefore have a very low Result.Confidence value.
Is there a way to simultaneously respond to two languages, such as by instantiating two CultureInfo classes:
CultureInfo ciEnglish = new CultureInfo("en-us");
CultureInfo ciSpanish = new CultureInfo("es-mx");
Even if that is doable, would the two classes be "willing" to share the microphone and be smart enough to cede to the other when they don't understand what is being spoken?
I'm fearful that this is going to be one of those "hard" (read "pretty much impossible") challenges. If I'm wrong in that, please let me know, though.
In the answer by Bulltorious here, it would seem that possibly a "SpeechRecognized" event could try to determine the language being spoken, but not enough code is shown to see whether that is really so.

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

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