none
I have a problem about .NET FrameWork and SYSTEM.speech reference RRS feed

  • Question

  • Hello I recently wrote a code in VS studio using System.speech But for some reason the sentences I have on the grammar is not recognized or even if they are I cant send / make the code type them into the rich text box.Does anyone have a solution

    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;
    using System.Speech.Recognition;
    using System.Speech.Synthesis;
    using System.Threading;
    using System.IO;

    namespace Deneme1
    {
        public partial class Form1 : Form
        {
            SpeechRecognitionEngine re = new SpeechRecognitionEngine();
            SpeechSynthesizer ss = new SpeechSynthesizer(); // When you want program to talk back to you
            public Form1()
            {
                InitializeComponent();

            }



            private void Form1_Load(object sender, EventArgs e)
            {
                //First of all storing commands
                Choices commands = new Choices();
                commands.Add(new string[] { "Blue On", "Red On", "Green On", "Blue Off", "Red Off", "Green Off", "Exit", "All On", "All Off", "Arduino Say Good Bye to makers" });

                //Now we will create object of Grammer in which we will pass commands as parameter
                GrammarBuilder grb = new GrammarBuilder();
                grb.Append(commands);
                Grammar gr = new Grammar(grb);

                re.LoadGrammarAsync(gr);
                re.SetInputToDefaultAudioDevice();// As Name suggest input device builtin microphone or you can also connect earphone etc...
                re.SpeechRecognized += re_SpeechRecognized;


            }

            void re_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
            {
                switch (e.Result.Text)
                {
                    ////For Led State ON
                    // For blue led
                    case "Blue On":
                        Thetextbox.Text += "\nBlue On";
                        break;

                    // For red led
                    case "Red On":
                        Thetextbox.Text += "\nRed On";

                        break;

                    // For green led
                    case "Green On":
                        Thetextbox.Text += "\nGreen On";
                        break;

                    //For Led State OFF
                    // For blue led
                    case "Blue Off":
                        Thetextbox.Text += "\nBlue Off";
                        break;

                    // For red led
                    case "Red Off":
                        Thetextbox.Text += "\nRed off";
                        break;

                    // For green led
                    case "Green Off":
                        Thetextbox.Text += "\nGreen off";
                        break;

                    //For turning ON all leds at once :)
                    case "All On":

                        break;

                    //For turning OFF all leds at once :)
                    case "All Off":

                        break;
                    //Program will talk back
                    case "Arduino Say Good Bye to makers":
                        ss.SpeakAsync("Good Bye Makers"); // speech synthesis object is used for this purpose
                        break;

                    // To Exit Program using Voice :)
                    case "Exit":
                        Application.Exit();
                        break;
                }

            }




            private void button1_Click(object sender, EventArgs e)
            {
                re.RecognizeAsync(RecognizeMode.Multiple);
                stop.Enabled = true;
                start.Enabled = false;
                MessageBox.Show("Voice Recognition Started !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            private void button2_Click(object sender, EventArgs e)
            {
                re.RecognizeAsyncStop();
                //btnStart.Enabled = true;
                stop.Enabled = false;
                start.Enabled = true;
            }
        }
    }

    Sunday, November 24, 2019 2:11 PM

Answers

  • Hi  Katıban The Great, 

    Try to check whether System.Speech dll exists in following path in your notebook.

    If it exists, add it. (right click your project -> Add -> Reference… -> Browse… -> [use the path to find and add it])

    If not, try the suggestion in the following reference.

    I can't find System.speech

    Beisdes, I find another related reference, and you can refer to it.

    Can't Use the System.Speech Namespace

    Hope them could be helpful.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 27, 2019 9:52 AM
    Moderator

All replies

  • Hi Katıban The Great, 

    Thank you for posting here.

    According to your question, I make a test based on your code, and I find the program works well, so I need more information to analyze your problem.

    >> for some reason the sentences I have on the grammar is not recognized or even if they are I cant send / make the code type them into the rich text box.

    Do you mean that the program cannot recognize the voice correctly? Could you describe more clearly about the sentence?

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 25, 2019 8:56 AM
    Moderator
  • hello Xingyu Zhao

    As far as I can understand my re_SpeechRecognized method is not working or the application is not taking the voice input for some reason.For example I changed the code to:

             void re_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
            {
                MessageBox.Show("Voice Recognition is working properly !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

    }

    So when a input comes/action happens a messagebox would pop up but it didnt work.The messagebox didnt appear. I do not know the reason of this

    by the way for your information:the  version I am  using for this app is .NET Framework 4.7.2 it didnt have the System.speech reference as default so I used it from another version 4.6 i think also I didnt downloaded any development kits such as SDK(Speech Developmetn Kit) or any other can any of these be the reason of the error?

    Thank you for your answer and support I will be waiting for any updates :)

    Monday, November 25, 2019 4:24 PM
  • Hi  Katıban The Great, 

    Thanks for your feedback.

    I change my .NET Framework version to 4.7.2, and make a test again. Program works well.

    >> it didnt have the System.speech reference

    I find ‘System.Speech’ reference in Reference Manager (right click your project -> Add -> Reference… -> Assemblies)

    I suggest you add ‘System.Speech’ reference in .NET Framework 4.7.2.

    Here’s my code:

            SpeechRecognitionEngine re = new SpeechRecognitionEngine();
            SpeechSynthesizer ss = new SpeechSynthesizer(); 
            private void Form1_Load(object sender, EventArgs e)
            {
                Choices commands = new Choices();
                commands.Add(new string[] { "Blue On", "Red On", "Green On", "Blue Off", "Red Off", "Green Off", "Exit", "All On", "All Off", "Arduino Say Good Bye to makers" });
                GrammarBuilder grb = new GrammarBuilder();
                grb.Append(commands);
                Grammar gr = new Grammar(grb);
                re.LoadGrammarAsync(gr);
                re.SetInputToDefaultAudioDevice();
                re.SpeechRecognized += re_SpeechRecognized;
            }
            void re_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
            {
               MessageBox.Show("Voice Recognition is working properly !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            private void button1_Click(object sender, EventArgs e)
            {
                re.RecognizeAsync(RecognizeMode.Multiple);
            }
    

    Hope it can help you.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 26, 2019 2:35 AM
    Moderator
  • Hello again

    After I saw your post about project running without a problem I tried to run it on another device(my desktop pc) and it worked! I copied the source folder,transferred it on a desktop computer, run it  on the same version of vs and it worked without a problem.The text has changed and it answered my questions.

    But whenever I try it on my laptop/notebook ,it doesnt work. So as far as I can tell cause of my problem is  something about my laptop.

    do you have any knowledge or solutions for this kind of error/problem?

    Thank you for your answer and support I will be waiting for any updates :)

    Tuesday, November 26, 2019 1:22 PM
  • Hi  Katıban The Great, 

    Try to check whether System.Speech dll exists in following path in your notebook.

    If it exists, add it. (right click your project -> Add -> Reference… -> Browse… -> [use the path to find and add it])

    If not, try the suggestion in the following reference.

    I can't find System.speech

    Beisdes, I find another related reference, and you can refer to it.

    Can't Use the System.Speech Namespace

    Hope them could be helpful.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 27, 2019 9:52 AM
    Moderator
  • well it is fixed now,it runs without a problem.

    thanks a lot for your suport :)

    Wednesday, November 27, 2019 6:37 PM