首页 > 解决方案 > 我收到错误“未安装识别模块”C# .Net 4.8 System.Speech.Recognition

问题描述

我正在尝试制作一个聊天机器人。我正在使用可以在“C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\Speech.dll”中找到的 Speech.dll

我成功实现了 Text-To-Speech,但现在我必须添加 Speech-To-Text,但它不起作用。我在代码的很多部分(如 loadGrammarAsync 或 SetInputToDefaultAudioDevice())上收到错误“未安装识别模块”。我遵循了很多教程,甚至是微软官方教程,但我无法摆脱这个错误。

我在某处读到需要安装 Microsoft Speech SDK,但在任何地方都找不到,当我点击 SDK 的 microsoft 页面上的链接时,我收到错误 404。

以下是我遵循的教程: https ://docs.microsoft.com/en-us/dotnet/api/system.speech.recognition.speechrecognitionengine?view=netframework-4.8

https://docs.microsoft.com/en-us/dotnet/api/system.speech.recognition.speechrecognitionengine.installedrecognizers?view=netframework-4.8

https://docs.microsoft.com/en-us/dotnet/api/system.speech.recognition.speechrecognitionengine.recognizerinfo?view=netframework-4.8

https://www.youtube.com/watch?v=AB9lfHDOe5U&t=0s

https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/speech-sdk?tabs=windows%2Cubuntu%2Cios-xcode%2Cmac-xcode%2Candroid-studio

这是 Speech-To-Text 的代码:

static void listenTest()
    {
        // Create an in-process speech recognizer for the en-US locale.  
        using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine())
        {
            try
            {
                // Create and load a dictation grammar.  
                recognizer.LoadGrammar(new DictationGrammar());
            }
            catch(Exception e)
            {
                Console.WriteLine("\n" + e);
            }

            // Add a handler for the speech recognized event.  
            recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);

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

            // Start asynchronous, continuous speech recognition.  
            recognizer.RecognizeAsync(RecognizeMode.Multiple);

            // Keep the console window open.  
            while (true)
            {
                Console.ReadLine();
            }
        }
}

static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
    Console.WriteLine("Recognized text: " + e.Result.Text);
}

我不知道我是否使用正确的方法来做到这一点。但是如果你知道另一种方法来解决这个问题,我想知道能够尝试一下

如果缺少某些内容,我可以编辑,我真的需要帮助。从现在开始我一直在努力解决这个问题 3 天

标签: c#.netspeech-recognitionchatbotspeech-to-text

解决方案


推荐阅读