2014-12-24 85 views
0

我试图在C#中识别语音,但它开始不好。我曾在YouTube上看过一些教程,但每次都会出现此错误。所以我得到了微软的MSDN代码,并试图在Google中找到一些解决方案。这是我使用的代码:错误“没有识别器安装”与识别语音

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); 
    } 

我已经下载了Microsoft Speech Platform SDKRuntime Languages(美国)。错误仍然存​​在。

我也已经用了这个代码,因为我在这里一个主题中的StackOverflow的看到:

sre = new SpeechRecognitionEngine(new CultureInfo("en-GB")); 

它没有工作,所以我试图用这个(我在MSDN看到):

SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")); 

当我尝试使用这些代码时,错误更改并说:“没有找到所需ID的识别器”。 我使用Windows 7(Home Basic,x64),Microsoft Visual C#2010 Express。我的默认语言(系统语言也是)是葡萄牙语(巴西),也许这是错误原因?那么,我希望我为你写的所有细节都明白。对不起,我的英语,我这训练,哈哈:P

+0

@Saruman我已经切换,错误更改为“没有找到所需ID的识别器”。在CultureInfo中(当我创建sre时)。我试图下载pt-BR文件,但也发生了。 如果我放弃它,错误将更改为“语音识别在此系统上不可用,无法找到SAPI和语音识别引擎”。 –

回答

1

运行以下确定识别您已经安装了什么,断点/调试和检查,如果你需要

foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers()) 
{ 
    System.Diagnostics.Debug.WriteLine(ri.Culture.Name); 
} 

和使用中所列的一个在SpeechRecognitionEngine构造函数

+2

那么,它没有回应单一的文化。如何进行? –