Grammar [en-us] to [en-gb]

本文关键字:to en-gb en-us Grammar | 更新日期: 2023-09-27 18:24:40

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

Grammar [en-us] to [en-gb]

您需要将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);
} 

您需要在当前线程上设置区域性,如下所示:

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