【问题标题】:I can't use speech recognition with C#. Why?我不能在 C# 中使用语音识别。为什么?
【发布时间】:2018-08-20 02:57:37
【问题描述】:

我想做一个语音识别软件,但是当我尝试做的时候总是得到同样的错误信息。

System.PlatformNotSupportedException:

我在stackoverflow上看到了同样的问题,我安装了东西,但问题仍然存在。下面是我的代码,这是堆栈溢出“解决方案”,对我不起作用:

PlatformNotSupportedException Using .NET Speech Recognition

是的,我安装了所有提到的东西......

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Speech.Recognition;
using System.Speech.Synthesis;

namespace SpeechExe
{
    class ExecuteSpeech
    {
        SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
        Choices choices = new Choices();
        GrammarBuilder gb = new GrammarBuilder();

        private void MakeCommands()
        {
            string[] commantList = { "say hello" };
            choices.Add(commantList);
            gb.Append(choices);
            Grammar grammar = new Grammar(gb);

            sre.LoadGrammarAsync(grammar);
            sre.SetInputToDefaultAudioDevice();
            sre.SpeechRecognized += Sre_SpeechRecognized;
        }

        private void Sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            switch(e.Result.Text)
            {
                case "say hello":
                    Console.WriteLine("Hello!");
                    break;
            }
        }

        public void Start()
        {
            this.MakeCommands();
            sre.RecognizeAsync(RecognizeMode.Multiple);
        }

    }
}

【问题讨论】:

  • 您在.LoadGrammarAsync(); 之前缺少sre.RequestRecognizerUpdate();。但是如果你不打电话给Start(),这并不重要。如果您使用的是 Window 7,这并不重要。在您的问题中添加一些详细信息:正在使用的系统(如果是 Win7,什么 Service Pack),针对 .Net FrameWork。在 Win 7 上,正如您在链接的 SO 问题中所见,您需要安装 Microsoft Speech Platform SDK。不仅仅是运行时,还有开发者工具(SDK)和一些声音。命名空间是:Microsoft.Speech.RecognitionMicrosoft.Speech.Synthesis
  • 我有 Windows 10 和 .Net 4.7。我调用了正确的命名空间,并安装了 SDK。
  • 哦,我没有 Microsoft.Speech.Recognition 命名空间和 dll。我只有 System.Speech.Recognition。我的意思是它在参考管理器中不存在。

标签: c# .net exception voice-recognition


【解决方案1】:

我将 Windows 的语言更改为英语,但没有收到此错误消息。 (是匈牙利语。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-20
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多