Does anyone know how to change recognition profiles from within a .NET application?
I am writing a .NET application that does speech recognition using the capabilities found in the System.Speech.Recognition namespace. The audio that I am feeding into the system comes from multiple different users. I would like to be able to train the system to more accurately recognize speech from each of the different users.
I have found the Speech Recognition control panel in windows (Windows 7 in this case) where I can configure training profiles. Setting up a profile for myself and doing the training process significantly improved the accuracy of the recognition. So I could setup profiles for every user and have them do the training process, but then I need to be able to select the right profile in my application.
My application is a "server" that receives audio streams from one or more users at a time and performs the speech recognition. So I need to be able to specify which recognition profile to use programmatically for each instance of the recognition engine that my application creates. This is not a single user application, so I can't just have them select their profile from the Windows control panel.
Enter speech recognition in the search box, and then tap or click Windows Speech Recognition. Say "start listening," or tap or click the microphone button to start the listening mode. Open the app you want to use, or select the text box you want to dictate text into. Say the text you want to dictate.
Speech recognition involves three processes: extraction of acoustic indices from the speech signal, estimation of the probability that the observed index string was caused by a hypothesized utterance segment, and determination of the recognized utterance via a search among hypothesized alternatives.
I don't see a way to do it via System.Speech.Recognition, but you can do it via speechlib (the SAPI IDispatch-compatible API). Look at ISpeechRecognizer::Profile.
To set the profile, you will need to add
using SpeechLib;
to your code, along with System.Speech.Recognition.
The tricky part would be getting the profile that you set via SpeechLib to 'stick' while you're creating the System.Speech.Recognition.RecognitionEngine. I'd probably set the profile to be default (via SpeechLib), create the RecognitionEngine, and reset the default profile.
(I'm assuming that you're not planning to use the shared recognizer, which won't work in a multiuser scenario.)
You'll probably need a critical section to make sure that only one thread can create the RecognitionEngine at a time.
You can use the registry to change the default profile. The registry contains list of profiles. You can easily add them via the speech properties dialog. Train the profile and its ready to use.
Change the default profile in the registry and start the speech engine and its is using that profile. This has work fordifferent windows versions, have not tried on multiple instances.
The registry Key is located at. HKEY_CURRENT_USER\Software\Microsoft\Speech\RecoProfiles Change the "DefaultTokenId" key value to HKEY_CURRENT_USER\Software\Microsoft\Speech\RecoProfiles\Tokens{7A8C84A3-44DA-488F-A27D-BC5BC326A8BE}
Here is how to look through profiles and set a profile as default.
RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Speech\RecoProfiles\Tokens");
_profiles = rk.GetSubKeyNames();
string findname = "{7A8C84A3-44DA-488F-A27D-BC5BC326A8BE}";
string name = "";
foreach (String s in _profiles)
{
using (RegistryKey sk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Speech\RecoProfiles\Tokens\" + s))
{
if (sk != null)
name = (string)sk.GetValue("");
if (name == findname) break;
}
}
RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Speech\RecoProfiles", true);
rk.SetValue("DefaultTokenId", @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Speech\RecoProfiles\Tokens\" + name);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With