1 year ago

#265872

test-img

Radek_Dom

C# Voice bot does not responding to my instructions

I wanted to try sound recognition in C#,but the program is not responding.I had a problem with the language before(my language is Czech),but I solved it by setting Culture.But no output comes out of the program.It does not respond to my instructions I also tested the microphone,but it is fine. Do you know what to do?

  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;

namespace Test_Bot
{
    public partial class Form1 : Form
    {
        SpeechRecognitionEngine engine =
    new SpeechRecognitionEngine(
      new System.Globalization.CultureInfo("en-GB"));
        public Form1()
        {
            InitializeComponent();
        }

        private void btnEnable_Click(object sender, EventArgs e)
        {
            engine.RecognizeAsync(RecognizeMode.Multiple);
            btnDisable.Enabled = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Choices commands = new Choices();
            commands.Add(new string[] { "Say hello", "Print my name" });
            GrammarBuilder gBuilder = new GrammarBuilder();
            gBuilder.Append(commands);
            Grammar grammar = new Grammar(gBuilder);

            engine.LoadGrammarAsync(grammar);
            engine.SetInputToDefaultAudioDevice();
            engine.SpeechRecognized += engine_SpeechRecognized;
        }

        void engine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {

            switch (e.Result.Text)
            {
                case "Say hello":
                    MessageBox.Show("Hi Peter");
                    break;

                case "Print my name":
                    richTextBox1.Text += "\nPeter";
                    break;
            }
        }

        private void btnDisable_Click(object sender, EventArgs e)
        {
            engine.RecognizeAsyncStop();
            btnDisable.Enabled = false;
        }

    }
}

c#

winforms

voice-recognition

voice

0 Answers

Your Answer

Accepted video resources