I´d like to try Speech recognition to controlling program. I wrote test program in C# and when I´m debugging this, an error occurred every time -
System.Runtime.InteropServices.COMException (0x80004005): Calling part of COM return error HRESULT E_FAIL.*
in System.Speech.Recognition.RecognizerBase.Initialize(SapiRecognizer recognizer, Boolean inproc)
in System.Speech.Recognition.SpeechRecognitionEngine.get_RecoBase()
in System.Speech.Recognition.SpeechRecognitionEngine.LoadGrammar(Grammar grammar)
It looks the error is caused by engine.LoadGrammar(new DictationGrammar());
On my notebook I installed CZECH OS Vista, and maybe this is the problem that speech recognition language is not the same as OS language.
Is there a way how to developing with system.speech in non english OS, or am I wrong in some step? There is no problem in language, I´d like use english for speech recognizing, but, I cannot get english Vista or MUI language pack.
Full code is below.
Thanks a lot!
using System;
using System.Windows;
using System.Speech.Recognition;
namespace rozpoznani_reci_WPF
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
SpeechRecognitionEngine engine = new SpeechRecognitionEngine();
try
{
engine.LoadGrammar(new DictationGrammar());
engine.SetInputToDefaultAudioDevice();
engine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
}
catch(Exception e)
{
//MessageBox.Show(e.ToString());
textBox1.Text = e.ToString();
}
}
void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result != null)
{
textBox1.Text = e.Result.Text + " ";
}
}
}
}
According to the MSDN documentation on DictationGrammar
, the argument-free constructor
Initializes a new instance of the DictationGrammar class for the default dictation grammar provided by Windows Desktop Speech Technology.
Is there a Czech language DicationGrammar
class available on your machine? If not, you need to create one and use the other constructor DictationGrammar(String)
and load one from a URI. You can also use GrammarBuilder
to construct your own and load it instead using SpeechRecognizer.LoadGrammar()
.
You might also find this link useful; it's from 2008, but you did ask about Vista. :-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.