.:: Jasa Membuat Aplikasi Website,Desktop,Android Order Now..!! | | Order Now..!! Jasa Membuat Project Arduino,Robotic,Print 3D ::.

C# :: Simple Speech Recognition Using C#

0 komentar


بِسْــــــــــــــــمِ اﷲِالرَّحْمَنِ اارَّحِيم
bismillaahirrahmaanirrahiim

السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
Assalamu'alaikum warahmatullahi wabarakatuh


HeadsetOk. I confess! I am a .NET junkie. It�s true. I have a real fetish for the framework. But, before you judge me, let me show you why. Better yet, let me show you an example of why I�m so fond of the Microsoft .NET Framework.
If any of you have ever done any kind of speech recognition or speech-to-text applications without using .NET, then you should already know how difficult it is to do. Even using libraries like Microsoft�s Speech API can be a real hassle. However, the .NET framework provides us with everything we need for creating speech-capable applications. The framework does all of the heavy lifting, leaving you with very minimum code to write. To prove it, I want to take a minute to show you a very simple C# application that can type out anything you say. So, let�s begin.
To begin this example, you will need to fire up Visual Studio and create a new Windows Application. Before writing any code, you will need to first add a reference to the System.Speech component. You can do this by right-clicking on �References� in your Solution Explorer and selecting �Add Reference��. When the �Add Reference� dialog appears, scroll down and select �System.Speech� and click the �OK� button.
Now that you have added a reference to the Speech component, you should go ahead and setup your form by double-clicking �Form1.cs� in the Solution Explorer. For this example, you will need to add a Rich TextBox control and 2 buttons, one for starting the speech recognition and the other for stopping it. You can combine these 2 buttons into 1 if you want. But for demo purposes, we will keep them separate. Here is what my form looks like if you need something to reference.
Speech Recognition Example Form
Once you have your form ready, it�s time to add some code. So, once again, click once on �Form1.cs� in your Solution Explorer and click the �View Code� button at the top.Visual Studio Solution Explorer - View CodeThe first thing you will need to add to your code is a reference to the System.Speech namespace we added earlier. You can do that by adding the following line to the top of your source code along with the other using statements.
using System.Speech.Recognition;
Next, you will need to setup a new SpeechRecognitionEngine object and since you�ll be reusing this object, you�ll need to add it as a global variable.
private SpeechRecognitionEngine recognitionEngine;
Now that you have your speech engine ready, you�ll need to instantiate and initialize it inside the form constructor.
recognitionEngine = new SpeechRecognitionEngine();
To keep things simple, you�ll also want to go ahead and set the input to use your computer�s default audio device. Lucky for us, .NET makes this step easy as well by calling the SetInputToDefaultAudioDevice method like so:
recognitionEngine.SetInputToDefaultAudioDevice();
While you�re at it, you�ll also want to add a new handler for whenever speech has been captured by adding the �SpeechRecognized� event. In that handler, you can do all kinds of things like checking the level of confidence that the engine has determined that each word actually is. You can change the minimum confidence level if you feel that the engine isn�t accurately recognizing your words. Also in that handler, you will want to go ahead and add any recognized words to the rich text box control you added to your form. As you�ll see in the code below, I named my rich text box �txtOutput�. But you can leave yours as the default or change it to whatever you want.
recognitionEngine.SpeechRecognized += (s, args) =>
{
foreach (RecognizedWordUnit word in args.Result.Words)
{
if (word.Confidence > 0.8f)
txtOutput.Text += word.Text + � �;
}
txtOutput.Text += Environment.NewLine;
};
After you�ve added a new event handler for printing detected text, you will need to load at least one grammar object by calling the LoadGrammar method and passing it a new DictationGrammar like this:
recognitionEngine.LoadGrammar(new DictationGrammar());
Not bad so far, huh? Well, the next 2 parts are extremely easy. All we have left to do now is to add the code needed to make tell our speech engine to begin listening and to stop listening. To do that, go to your form and double click the Start button to add a click event handler to the button. Inside your click event handler, the only thing you need to do is call the RecognizeAsync method. You will also need to tell it which RecognizeMode to use: either Single or Multiple. I use multiple so that the engine will listen for entire sentences before processing the input.
recognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
The only thing you have left to do now is tell the engine to stop listening by calling RecognizeAsyncStop from your Stop button click event handler.
recognitionEngine.RecognizeAsyncStop();
That�s it! You now have everything need for capturing speech and displaying it in a Rich TextBox by using the .NET Speech component and C#. Go ahead and test it by running the application and clicking the Start button. That will tell the engine to start listening for speech. At this point, go ahead and do some talking. If everything went as described, you should see your words typed out in the text box. If you do not see your words being typed out, make sure that your microphone is not muted and that the volume of it is turned up loud enough. If the engine isn�t doing a good enough job of recognizing your words, try changing the confidence level as mentioned above.
Below you will find the complete source code for this project. Tomorrow, I will expand on this tutorial by showing you how to listen for specific commands and performing different tasks based on those commands. For example, I will show you how to listen for names of applications and how to open the applications that correspond to those names.
01using System;
02using System.Collections.Generic;
03using System.ComponentModel;
04using System.Data;
05using System.Drawing;
06using System.Linq;
07using System.Text;
08using System.Windows.Forms;
09using System.Speech.Recognition;
10 
11namespace SpeechRecognitionExample
12{
13    public partial class Form1 : Form
14    {
15        private SpeechRecognitionEngine recognitionEngine;
16 
17        public Form1()
18        {
19            InitializeComponent();
20 
21            recognitionEngine = new SpeechRecognitionEngine();
22            recognitionEngine.SetInputToDefaultAudioDevice();
23            recognitionEngine.SpeechRecognized += (s, args) =>
24            {
25                foreach (RecognizedWordUnit word in args.Result.Words)
26                {
27                    if (word.Confidence > 0.8f)
28                        txtOutput.Text += word.Text + " ";
29                }
30                txtOutput.Text += Environment.NewLine;
31            };
32            recognitionEngine.LoadGrammar(new DictationGrammar());
33        }
34 
35        private void btnStart_Click(object sender, EventArgs e)
36        {
37            recognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
38        }
39 
40        private void btnStop_Click(object sender, EventArgs e)
41        {
42            recognitionEngine.RecognizeAsyncStop();
43        }
44    }
45}

Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
NB :: Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code, membeli hardware elektronika untuk kepentingan Perusahaan maupun Tugas Akhir (TA/SKRIPSI), Insyaallah Saya siap membantu, untuk Respon Cepat dapat menghubungi kami, melalui :

No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com


atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :

ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِين
Alhamdulilah hirobil alamin

وَ السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
wassalamualaikum warahmatullahi wabarakatuh


Artikel C# :: Simple Speech Recognition Using C#, Diterbitkan oleh scodeaplikasi pada Rabu, 24 Agustus 2016. Semoga artikel ini dapat menambah wawasan Anda. Website ini dipost dari beberapa sumber, bisa cek disini sumber, Sobat diperbolehkan mengcopy paste / menyebar luaskan artikel ini, karena segala yang dipost di public adalah milik public. Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code ,Dengan Cara menghubungi saya Ke Email: Fajarudinsidik@gmail.com, atau No Hp/WA : (fajar) : 085369237896, (puat) : 085267792168.

Tawk.to