Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

C# System.Speech

Hi,

I'm trying to use the System.Speech.Recognition; but every time I'm getting different exceptions (even when using examples from MSDN).

When using this example (https://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognizer(v=vs.110).aspx) I'm getting this:

System.PlatformSupportedException: There is not installed any recognitionprogram. At System.Speech.Recognition.RecognizerBase.Initialize(SapiRecognizer recognizer, boolean inproc) At System.Speech.Recognition.SpeechRecognizer.get_RecoBase() At System.Speech.Recognition.SpeechRecognizer.LoadGrammar(Grammar grammar) At SharedRecognizer.Program.Main(String[] args) i D:\Projects....: line 25

I've been reading hundreds of guides and watched billions of videos on youtube to see if I could find a solution to this, but no luck so far :-/

I'm really hoping someone in here have an idea how to fix this.

code from the link above

using System;
using System.Speech.Recognition;
using System.Threading;

namespace SharedRecognizer
{
  class Program
  {

    // Indicate whether the asynchronous emulate recognition
    // operation has completed.
    static bool completed;

    static void Main(string[] args)
    {

      // Initialize an instance of the shared recognizer.
      using (SpeechRecognizer recognizer = new SpeechRecognizer())
      {

        // Create and load a sample grammar.
        Grammar testGrammar =
          new Grammar(new GrammarBuilder("testing testing"));
        testGrammar.Name = "Test Grammar";
        recognizer.LoadGrammar(testGrammar);

        // Attach event handlers for recognition events.
        recognizer.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(
            SpeechRecognizedHandler);
        recognizer.EmulateRecognizeCompleted +=
          new EventHandler<EmulateRecognizeCompletedEventArgs>(
            EmulateRecognizeCompletedHandler);

        completed = false;

        // Start asynchronous emulated recognition. 
        // This matches the grammar and generates a SpeechRecognized event.
        recognizer.EmulateRecognizeAsync("testing testing");

        // Wait for the asynchronous operation to complete.
        while (!completed)
        {
          Thread.Sleep(333);
        }

        completed = false;

        // Start asynchronous emulated recognition.
        // This does not match the grammar or generate a SpeechRecognized event.
        recognizer.EmulateRecognizeAsync("testing one two three");

        // Wait for the asynchronous operation to complete.
        while (!completed)
        {
          Thread.Sleep(333);
        }
      }

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

    // Handle the SpeechRecognized event.
    static void SpeechRecognizedHandler(
      object sender, SpeechRecognizedEventArgs e)
    {
      if (e.Result != null)
      {
        Console.WriteLine("Recognition result = {0}",
          e.Result.Text ?? "<no text>");
      }
      else
      {
        Console.WriteLine("No recognition result");
      }
    }

    // Handle the SpeechRecognizeCompleted event.
    static void EmulateRecognizeCompletedHandler(
      object sender, EmulateRecognizeCompletedEventArgs e)
    {
      if (e.Result == null)
      {
        Console.WriteLine("No result generated.");
      }

      // Indicate the asynchronous operation is complete.
      completed = true;
    }
  }
}

1 Answer

James Churchill
STAFF
James Churchill
Treehouse Teacher

Henrik,

Did you manage to resolve the issue that you were encountering? If not, what version of Windows are you using? Did the above code always throw the same exception? Or did it sometimes work without any errors?

Thanks ~James

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

Hi James,

Yeah I got pretty much the same exception every time, but I made it work after a couple of days by installing the english version of Windows :-) I find it odd that the english version got speechrecognition but the danish version dont :-/