locked
C# - .NET 4.5 Speech Recognition problems RRS feed

  • Question

  • Hello, my name's Jake Cross! I've recently ran into a problem when I upgrade to Visual Studio 2013 running .NET 4.5. I've been using Sharp-develop for programming C# with the .NET 4.0 framework but and it was working fine with the exact same code. I'm unsure why this is, I don't believe it's because of my new laptop and I've made sure my mic was set to the default audio input device. Here's the code. 
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.IO;
    using System.Speech.Recognition;
    using System.Speech.Synthesis;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace J.A.R.V.I.S
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            SpeechRecognitionEngine jListen = new SpeechRecognitionEngine();
            SpeechSynthesizer jTalk = new SpeechSynthesizer();
    
            private void Form1_Load(object sender, EventArgs e)
            {
                jListen.SetInputToDefaultAudioDevice();
                jListen.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Program Files\Stackoverload\Jarvis\Grammar\English.txt")))));
                jListen.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(jListen_SpeechRecognized);
                jListen.RecognizeAsync(RecognizeMode.Multiple);
            }
    
            void jListen_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
            {
                string speech = e.Result.Text;
    
                if(speech == "hello")
                {
                    jTalk.Speak("Hi");
                }
    
            }
        }
    }
    Thanks ahead of time! 
    Friday, January 10, 2014 1:11 AM

Answers

  • Hello,

    >>I've recently ran into a problem when I upgrade to Visual Studio 2013 running .NET 4.5.

    What is the problem? As far as I know, Speech Recognition is supported in .Net Framework 4.5. And the codes seem to be ok.

    >>I'm unsure why this is, I don't believe it's because of my new laptop and I've made sure my mic was set to the default audio input device.

    Have a try to work with your before machine which works fine with .Net Framework 4 and change the PlatForm Target to .Net Framework 4.5 to see whether it will work.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 13, 2014 9:20 AM

All replies

  • One more thing, I also made sure my Grammar text file had "hello" without the quotes and was located in the directory also.
    Friday, January 10, 2014 1:12 AM
  • Hello,

    >>I've recently ran into a problem when I upgrade to Visual Studio 2013 running .NET 4.5.

    What is the problem? As far as I know, Speech Recognition is supported in .Net Framework 4.5. And the codes seem to be ok.

    >>I'm unsure why this is, I don't believe it's because of my new laptop and I've made sure my mic was set to the default audio input device.

    Have a try to work with your before machine which works fine with .Net Framework 4 and change the PlatForm Target to .Net Framework 4.5 to see whether it will work.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 13, 2014 9:20 AM
  • Hello, I am from .NET Framework Compatibility team. I would like to understand this better and help. Could you contact me on netfx45compat at Microsoft dot com to discuss?

    Thanks,

    Varun


    Varun Gupta - MSFT

    Wednesday, January 22, 2014 12:50 AM
  • void jListen_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { string speech = e.Result.Text.ToString(); //important to use .ToString() if(speech == "hello") { jTalk.Speak("Hi"); } }


    hi

    i have a similar problem.

    but first of all:

    the .ToString() is quite important

    second: Pay attention for small and big letters! If you have in your grammar: "Hello" and in your script

    "hello", it doesn't recognize it.

    i am working on a jarvis project too and have now to rewrite everything for the fourth time!, because my grammar loading did not work (one time it had another reason)

    so just open a new project, write all the general things by hand!( do not copy paste, it doensbt work) and copy paste your
            void jListen_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)

    by the way: If you want to have nice voices go to ivona.com and just test some voices. I don't think i'll buy them, but they sound much better and natural

    yours faithfully Marco Cacciatore

    Monday, July 7, 2014 11:15 PM