Click here to Skip to main content
15,925,255 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;

namespace speech2textt
{
    public partial class Form1 : Form
    {
        public Form1()
        {
             InitializeComponent();
        }


        SpeechRecognitionEngine Engine = new SpeechRecognitionEngine();
        DictationGrammar Grammar = new DictationGrammar();
    private void button1_Click(object sender, EventArgs e)
        {
            SpeechRecognitionEngine rec = new SpeechRecognitionEngine();

            rec.LoadGrammar(new Grammar(new GrammarBuilder("exit"))); // load grammar
            // rec.GrammarBuilder.Append(string);
            rec.LoadGrammar(new DictationGrammar());

            rec.SpeechRecognized += speech1;
            Engine.BabbleTimeout = TimeSpan.FromSeconds(10.0);
            Engine.EndSilenceTimeout = TimeSpan.FromSeconds(10.0);
            Engine.EndSilenceTimeoutAmbiguous = TimeSpan.FromSeconds(10.0);
            Engine.InitialSilenceTimeout = TimeSpan.FromSeconds(10.0);

            rec.SetInputToDefaultAudioDevice(); // set input to default audio device
            rec.RecognizeAsync(RecognizeMode.Multiple); // recognize speech

        }

    void speech1(object sender, SpeechRecognizedEventArgs e)
    {
        if (e.Result.Text == "exit")
        {
            Application.Exit();
        }
        else
        {
            richTextBox1.AppendText(" " +e.Result.Text);
        }

    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }


    }
}
Posted
Comments
[no name] 14-Mar-13 11:38am    
How would you suppose that we know what it is that you said and what was displayed in the richTextBox1? A code dump is not a question or description of a problem.

Basically, you have done it correctly. This is a problem of the engine itself. You cannot do much about that. You can wait until the technology advances more, or use a commercial product which promises better quality if dictation recognition.

—SA
 
Share this answer
 
Since the speech recognition engine is a "blackbox" for which there is no opening to tinker with it, you have one very simple solution to the problem:

Speak slowly and clearly, trying to minimize any possible heavy accent.


OR, use a commerically available speech recognition library with a better engine. This will most likely not be free of charge.
 
Share this answer
 
Comments
depak gupta 14-Mar-13 16:26pm    
sir, I have one speech recognition library but don't know how to implement it if you can write down the steps I will follow it.
Dave Kreskowiak 14-Mar-13 18:32pm    
I can't. I don't know what you're doing with this library and I don't know the library itself. Your best source of information is the documentation on that library and the support forums dedicated to it on the manufacturers web site.
depak gupta 15-Mar-13 12:31pm    
sir, if I want to use my command to click button events,so can you please provide me logic behind this.
Dave Kreskowiak 15-Mar-13 18:27pm    
Try reading the documentation on Button:

http://msdn.microsoft.com/en-us/library/system.windows.forms.button.performclick.aspxhttp://msdn.microsoft.com/en-us/library/system.windows.forms.button.performclick.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900