语法[en-us]到[en-gb]

时间:2013-07-24 16:21:30

标签: c# speech-recognition

我需要帮助将我的代码中的语法类型设置为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我知道它与“文化”有关。你可能比我更了解,因为我是新手。我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

您需要set the culture on your GrammarBuilder到en-GB

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

答案 1 :(得分:0)

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

System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-GB");