1

我需要帮助将我的代码中的语法类型设置为 en-GB,因为默认情况下它是 en-US。这是代码:

private void Form1_Load(object sender, EventArgs e)
    {
        _recognizer.SetInputToDefaultAudioDevice();
        _recognizer.LoadGrammar(new DictationGrammar());
        _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Users\Tahmid\Documents\Commands.txt")))));
        _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
        _recognizer.RecognizeAsync(RecognizeMode.Multiple);
    } 

我已经对该主题进行了一些研究,并且因为我正在使用System.Speech.Recognition我知道它与“文化”有关。您可能会比我了解更多,因为我对此并不陌生。我该如何解决这个问题?

4

2 回答 2

1

您需要在to en-GB上设置文化GrammarBuilder

private void Form1_Load(object sender, EventArgs e)
{
    _recognizer.SetInputToDefaultAudioDevice();
    _recognizer.LoadGrammar(new DictationGrammar());
    var grammarBuilder = new GrammarBuilder(
              new Choices(
              File.ReadAllLines(
                @"C:\Users\Tahmid\Documents\Commands.txt")));
    grammarBuilder.Culture = new System.Globalization.CultureInfo("en-GB");
    _recognizer.LoadGrammar(new Grammar(grammarBuilder));
    _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
    _recognizer.RecognizeAsync(RecognizeMode.Multiple);
} 
于 2013-07-24T16:26:14.430 回答
0

您需要在当前线程上设置文化,如下所示:

System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-GB");
于 2013-07-24T16:24:44.407 回答