Jump to content
9 hours ago, alex75871 said:

Try running VS as administrator? Your program in debug mode will inherit the IDEs permissions by default.

Thanks...but i had to install speech SDK so that error is fixed, i think. But anyway i get another error saying that at least one grammar must be loaded before recognising but i have one loaded so i don't understand.

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

namespace Speech_Recognition_test_3
{
    public partial class Form1 : Form
    {
        private static SpeechSynthesizer synth = new SpeechSynthesizer();
        private static SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //ko klikneš začne poslušati
            recEngine.RecognizeAsync(RecognizeMode.Multiple);
            //enable-a drugi button
            button2.Enabled = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Choices toDo = new Choices();
            toDo.Add(new string[] { "open itunes", "open chrome", "open file explorer" });

            //naredi grammar ki ga program uporablja za preverjanje izgoverjene besede
            GrammarBuilder grammarBuilder = new GrammarBuilder();
            grammarBuilder.Append(toDo);
            Grammar grammar = new Grammar(grammarBuilder);

            //Začne uporabljati grammar
            recEngine.LoadGrammarAsync(grammar);
            //Tu se določi default naprava za snemanje
            recEngine.SetInputToDefaultAudioDevice();
            recEngine.SpeechRecognized += recEngine_SpeechRecognised;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            recEngine.RecognizeAsyncStop();
        }

        public static void recEngine_SpeechRecognised(object sender, SpeechRecognizedEventArgs e)
        {
            switch (e.Result.Text)
            {
                
                case "open itunes":
                    MessageBox.Show("Opening iTunes");
                    break;
                case "open chrome":
                    MessageBox.Show("Opening Google Chrome");
                    break;
                case "open file explorer":
                    MessageBox.Show("I cant do that");
                    break;
            }
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello World!");
        }
    }
}

 

 

loadAGrammar.PNG

Link to comment
https://linustechtips.com/topic/551856-visual-c-problem/#findComment-7292062
Share on other sites

Link to post
Share on other sites

24 minutes ago, Peder said:

Thanks...but i had to install speech SDK so that error is fixed, i think. But anyway i get another error saying that at least one grammar must be loaded before recognising but i have one loaded so i don't understand.

Are you ever calling Form1_Load where you load the grammar?

1474412270.2748842

Link to comment
https://linustechtips.com/topic/551856-visual-c-problem/#findComment-7292190
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×