System.ArgumentException: '找不到所需的ID识别函数。参数名称:文化 '

问题描述 投票:0回答:1

我得到了这个期望,但不知道如何解决它。

我试过将文化改为fi-FI、en-EN、en-GB、en-US,但总是出现这种情况。

我也试过 不支持文化 溶液和 Go to Debug -> Options -> Debugging and tick "Enable Just My Code" 这个.

.NET框架4.7.2Visual studio 2019参考系统.语音。

using System;
using System.Speech.Recognition;

namespace SpeechRecognition3
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create an in-process speech recognizer for the en-US locale.  
            using (SpeechRecognitionEngine recognizer =
              new SpeechRecognitionEngine(
                new System.Globalization.CultureInfo("fi-FI")))
            {

                // Create and load a dictation grammar.  
                recognizer.LoadGrammar(new DictationGrammar());

                // Configure input to the speech recognizer.  
                recognizer.SetInputToDefaultAudioDevice();

                // Modify the initial silence time-out value.  
                recognizer.InitialSilenceTimeout = TimeSpan.FromSeconds(5);

                // Start synchronous speech recognition.  
                RecognitionResult result = recognizer.Recognize();

                if (result != null)
                {
                    Console.WriteLine("Recognized text = {0}", result.Text);
                }
                else
                {
                    Console.WriteLine("No recognition result available.");
                }
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
    }
}

c# speech-recognition cultureinfo system.speech.recognition
1个回答
0
投票

我建议你看一下它的文档https:/docs.microsoft.comen-usdotnetapisystem.globalization.cultureinfo?view=netcore-3.1。

"基于RFC 4646的文化名称的格式是languagecode2>-countryregioncode2,其中languagecode2是两个字母的语言代码,countryregioncode2是两个字母的子文化代码。"

© www.soinside.com 2019 - 2024. All rights reserved.