2

I'd like to make a speech recognition software, but I always get the same error message, when I try to.

System.PlatformNotSupportedException:

I saw the same problem on stackoverflow, I installed the stuffs, but the problem is still exists. Here's my code below, and this is the stack overflow "solution", what not works for me:

PlatformNotSupportedException Using .NET Speech Recognition

Yes, I installed every mentioned stuffs...

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

    }
}
Kovoliver
  • 238
  • 2
  • 13
  • 1
    You are missing `sre.RequestRecognizerUpdate();` before `.LoadGrammarAsync();`. But this doesn't matter if you don't call `Start()`. Which doesn't rally matter if you are using Window 7. Add some details in your question: The System in use (if Win7, what Service Pack), targeted .Net FrameWork. On Win 7, as you have seen in the SO question you linked, you need to Install `Microsoft Speech Platform SDK`. Not just the Run-Time, but also the Developers Tools (SDK) and some voices. The Namespaces are: `Microsoft.Speech.Recognition` and `Microsoft.Speech.Synthesis` – Jimi Aug 20 '18 at 03:17
  • I have Windows 10, and .Net 4.7. I called the right namespaces, and I installed the SDK. – Kovoliver Aug 20 '18 at 06:51
  • Oh, and I don't have Microsoft.Speech.Recognition namespace, and dll. I have just System.Speech.Recognition. I mean it doesn't exist in the reference manager. – Kovoliver Aug 20 '18 at 07:43

1 Answers1

2

I changed the windows's language to english, and I don't get this error message. (It was Hungarian.)

Kovoliver
  • 238
  • 2
  • 13