exception error on new program

Pretendor

New member
Joined
Apr 18, 2020
Messages
3
Programming Experience
Beginner
Hi there,

i am new to C# and like to challenge myself, however i have wrote an script for voice commands and response. basicly an Siri of Hello Google.

what i intent to do is write a program that helps my mother do things on the computer by voice,, i know there are program's out there who can do the same, but the most are high overprised and as i mentions earlier i like to challenge myself and start learning c# and all its possibility,

i'am well known with powershell and for what i have done now the c# is a good look a like of powershell..

see below my error in the program (sorry it is a dutch error message)

ystem.PlatformNotSupportedException: Er is geen herkenner geïnstalleerd. (No recognizer is installed.)
bij System.Speech.Recognition.RecognizerBase.Initialize(SapiRecognizer recognizer, Boolean inproc)
bij System.Speech.Recognition.SpeechRecognitionEngine.get_RecoBase()
bij System.Speech.Recognition.SpeechRecognitionEngine.SetInputToDefaultAudioDevice()
bij Sarah.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\dj__d\source\repos\Sarah\Sarah\Form1.cs:regel 33
bij System.Windows.Forms.Form.OnLoad(EventArgs e)
bij System.Windows.Forms.Form.OnCreateControl()
bij System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
bij System.Windows.Forms.Control.CreateControl()
bij System.Windows.Forms.Control.WmShowWindow(Message& m)
bij System.Windows.Forms.Control.WndProc(Message& m)
bij System.Windows.Forms.ScrollableControl.WndProc(Message& m)
bij System.Windows.Forms.Form.WmShowWindow(Message& m)
bij System.Windows.Forms.Form.WndProc(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bij System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Geladen assembly's **************
mscorlib
Assembly-versie: 4.0.0.0
Win32-versie: 4.8.4150.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
Sarah
Assembly-versie: 1.0.0.0
Win32-versie: 1.0.0.0
CodeBase: file:///C:/Users/dj__d/source/repos/Sarah/Sarah/bin/Debug/Sarah.exe
----------------------------------------
System.Windows.Forms
Assembly-versie: 4.0.0.0
Win32-versie: 4.8.4150.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly-versie: 4.0.0.0
Win32-versie: 4.8.4001.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly-versie: 4.0.0.0
Win32-versie: 4.8.3752.0 built by: NET48REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Speech
Assembly-versie: 4.0.0.0
Win32-versie: 4.8.3752.0 built by: NET48REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Speech/v4.0_4.0.0.0__31bf3856ad364e35/System.Speech.dll
----------------------------------------
System.Configuration
Assembly-versie: 4.0.0.0
Win32-versie: 4.8.3752.0 built by: NET48REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
Assembly-versie: 4.0.0.0
Win32-versie: 4.8.4121.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
Assembly-versie: 4.0.0.0
Win32-versie: 4.8.3752.0 built by: NET48REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
mscorlib.resources
Assembly-versie: 4.0.0.0
Win32-versie: 4.8.3752.0 built by: NET48REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_nl_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.Speech.resources
Assembly-versie: 4.0.0.0
Win32-versie: 4.8.3752.0 built by: NET48REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Speech.resources/v4.0_4.0.0.0_nl_31bf3856ad364e35/System.Speech.resources.dll
----------------------------------------
System.Windows.Forms.resources
Assembly-versie: 4.0.0.0
Win32-versie: 4.8.3752.0 built by: NET48REL1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_nl_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------

************** JIT-foutopsporing **************
Als u JIT-foutopsporing wilt inschakelen, moet in het configuratiebestand voor deze
toepassing of computer (machine.config) de waarde
jitDebugging in het gedeelte system.windows.forms zijn ingesteld.
De toepassing moet ook zijn gecompileerd terwijl foutopsporing
was ingeschakeld.

Bijvoorbeeld:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

Wanneer JIT-foutopsporing is ingeschakeld, worden onverwerkte uitzonderingen
naar het JIT-foutopsporingsprogramma gestuurd dat op de computer is geregistreerd
en worden niet door dit dialoogvenster verwerkt.




+ RecognizerInfo '_recognizer.RecognizerInfo' threw an exception of type 'System.InvalidOperationException' System.Speech.Recognition.RecognizerInfo {System.InvalidOperationException}
 
That doesn't tell us a lot about the code causing the issue. Regarding the errors see



Try debugging your code and see if you can replicate the error, and report back with that problematic code.
 
ystem.PlatformNotSupportedException: Er is geen herkenner geïnstalleerd. (No recognizer is installed.)
I think that error message says it all. There is no Dutch language recognizer installed.
 
I found this in an old App I done for a customer. It was for a AI Voice Speech Recognition program, and I needed to check which cultures were installed... If you want to check which ones you have installed you can put this after your initialising method or somewhere that it will execute :
C#:
            IEnumerator<RecognizerInfo> Installed_Recognoizer = SpeechRecognitionEngine.InstalledRecognizers().GetEnumerator();
            while (Installed_Recognoizer.MoveNext())
            {
                Debug.WriteLine(Installed_Recognoizer.Current.Culture.Name);
            }

You will also need to use the using System.Diagnostics; using directive to print to your Output tab in Visual Studio.

If it lists your culture, then you have underlying issues which will require you to look a little deeper at the environments in which you're installing or running the software.

This will list all of the ones installed on the system it's running on. However, you can bundle your software with the required recognizer for the languages you with to target. This can be done by whatever installer you use.
 
Hmm, at a quick glance of problems people have reported. Some people have the language packs installed, but still experience the same problem as you are reporting.

Some people fixed this issue by using : Microsoft.Speech and not : System.Speech. While this may not be your issue, it is worth checking that you are using the correct using directives. Because System.Speech is used for the speech SDK and not the speech engine from Microsoft.
 
when i run the program i will get this.

C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sarah
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());   (X)
        }
    }
}

(X) is the error and give exception unhandeld.

System.PlatformNotSupportedException: 'Er is geen herkenner geïnstalleerd. '
 
Last edited by a moderator:
i will post the whole script, maybe one of you guys will see the problem.

C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.IO;
using System.Diagnostics;

namespace Sarah
{
    public partial class Form1 : Form
    {
        SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
        SpeechSynthesizer Sarah = new SpeechSynthesizer();
        SpeechRecognitionEngine startlistening = new SpeechRecognitionEngine();
        Random rnd = new Random();
        int RecTimeOut = 0;
        DateTime TimeNow = DateTime.Now;

        public Form1()
        {
            InitializeComponent();
            IEnumerator<RecognizerInfo> Installed_Recognoizer = SpeechRecognitionEngine.InstalledRecognizers().GetEnumerator();
            
            while (Installed_Recognoizer.MoveNext())
            {
                Debug.WriteLine(Installed_Recognoizer.Current.Culture.Name);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            _recognizer.SetInputToDefaultAudioDevice();
            _recognizer.LoadGrammarAsync(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"DefaultCommands.txt")))));
            _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(Default_SpeechRecognized);
            _recognizer.SpeechDetected += new EventHandler<SpeechDetectedEventArgs>(_recognizer_SpeechRecognized);
            _recognizer.RecognizeAsync(RecognizeMode.Multiple);

            startlistening.SetInputToDefaultAudioDevice();
            startlistening.LoadGrammarAsync(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"DefaultCommands.txt")))));
            startlistening.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(startlistening_SpeechRecognized);
        }

        private void Default_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            int ranNum;
            string speech = e.Result.Text;

            if (speech == "Hallo")
            {
                Sarah.SpeakAsync("Hallo, ik luister");
            }
            if (speech == "Hoe gaat het met je")
            {
                Sarah.SpeakAsync("ik werk naar behoren");
            }
            if (speech == "Hoelaat is het")
            {
                Sarah.SpeakAsync(DateTime.Now.ToString("HH mm"));
            }
            if (speech == "Stop met praten")
            {
                Sarah.SpeakAsyncCancelAll();
                ranNum = rnd.Next(1, 2);
                
                if (ranNum == 1)
                {
                    Sarah.SpeakAsync("Oke Jeffrey");
                }
                if (ranNum == 2)
                {
                    Sarah.SpeakAsync("Het spijt me ik zal stil zijn");
                }
            }
            if (speech == "Stop met luisteren")
            {
                Sarah.SpeakAsync("Roep maar als je me nodig hebt");
                _recognizer.RecognizeAsyncCancel();
                startlistening.RecognizeAsync(RecognizeMode.Multiple);
            }
            if (speech == "Laat commandos zien")
            {
                string[] commands = (File.ReadAllLines(@"DefaultCommands"));
                Lstcommands.Items.Clear();
                Lstcommands.SelectionMode = SelectionMode.None;
                Lstcommands.Visible = true;
                foreach (string command in commands)
                {
                    Lstcommands.Items.Add(command);
                }
            }
            if (speech == "Verberg commandos")
            {
                Lstcommands.Visible = false;
            }
        }
        
        private void _recognizer_SpeechRecognized(object sender, SpeechDetectedEventArgs e)
        {
            RecTimeOut = 0;
        }
        
        private void startlistening_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            string speech = e.Result.Text;

            if (speech == "Wakker worden")
            {
                startlistening.RecognizeAsyncCancel();
                Sarah.SpeakAsync("Ja, ik luister");
                _recognizer.RecognizeAsync(RecognizeMode.Multiple);
            }
        }

        private void TmrSpeaking_Tick(object sender, EventArgs e)
        {
            if (RecTimeOut == 10)
            {
                _recognizer.RecognizeAsyncCancel();
            }
            else if (RecTimeOut == 11)
            {
                TmrSpeaking.Stop();
                startlistening.RecognizeAsync(RecognizeMode.Multiple);
                RecTimeOut = 0;
            }
        }
    }
}
 
Last edited by a moderator:
Please don't code dump like that. I didn't need to see the code.

The snipped I gave you on post #4 was for you to run and report back what gets wrote to the output window on Visual Studio. Can you copy and paste the relevant printed output regarding what cultures are installed?

The code i gave you will tell you this, If you press Ctrl + O it will open the Output window if its not already open.

Also see : Voice Recognition - Speech Recognition with .NET Desktop Applications As It's a hunch to what might be wrong, as pointed out on post #5. There is a difference between the two different namespaces and which using directive you should be using.
 
Back
Top Bottom