What You Say Is What I Speak(WYSWIS)

Rajnilari2015
Posted by in C# category on for Beginner level | Points: 250 | Views : 883 red flag

What You Say Is What I Speak(WYSWIS) is a simple windows application in which the computer utters the voice of a human what the later says.


 Download source code for What You Say Is What I Speak(WYSWIS)

Introduction

What You Say Is What I Speak(WYSWIS) is a simple windows application in which the computer utters the voice of a human what the later says.

It is a simple windows application built by using SpeechRecognitionEngine class . The advantage being it is independent of Windows Speech Recognition.So let is play for fun.

Straight to Experiment (Step by step)

Open VS and fire a windows application. Add a reference to System.Speech dll. Then add a Buttomn and a TextBox(ReadOnly) in the form Designer s under

Then we will follow the below steps

Step 1: Initialize the Speech Recognition Engine.

listener = new SpeechRecognitionEngine();

Step 2: Create a speech recognition grammar.

var grammer = CreateSpeechRecognitionGrammer();

The implementation for the function CreateSpeechRecognitionGrammer is given below

private Grammar CreateSpeechRecognitionGrammer()
{
	var alternatives = new Choices();
	alternatives.Add(phrases);

	GrammarBuilder builder = new GrammarBuilder(alternatives);
	builder.AppendDictation();

	Grammar grammar = new Grammar(builder);

	return grammar;
}

Step 3: Load the grammar into the Speech Recognition Engine

listener.LoadGrammar(grammer);

Step 4: Configures Speech Recognition Engine to receive input from the default audio device

listener.SetInputToDefaultAudioDevice();

Step 5: Register for Speech Recognition event notification

listener.SpeechRecognized += Listener_SpeechRecognized;

Step 6: Create a handler for the speech recognition event

private void Listener_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
	button1.Enabled = true;
	txtInteractiveMessage.Visible = false;
	MessageBox.Show("You said : " + RemoveOutliers(e.Result.Text));
}

The implementation for the function RemoveOutliers is given below

private string RemoveOutliers(string inputText)
{
	var matchedWord = string.Empty;
	foreach (var word in phrases)
	{
		if (inputText.Contains(word))
		{
			matchedWord = word;
			break;
		}
	}
	return matchedWord;
}

In statistics, an outlier is an observation point that is distant from other observations.In simple words it's a noise that we need to remove.

Step 7: Perform speech recognition operations

listener.RecognizeAsync(RecognizeMode.Multiple);

Run the application

Now that we have build our application, it's time to run and test it. When the form loads it looks as under

User clicks on the Start Speaking button and the forms changes to

The system is asking the user Keep Speaking ... computer is trying to understand the word / phrase

As soon as the computer recognizes a phrase,it displays the user with the same word that the later uttered.

Reference

SpeechRecognitionEngine

Conclusion

This article is an attempt to build a simple speech synthesizer using SpeechRecognitionEngine class. We can make it robust by making a chatter bot application. A deep understanding of the same needs more research and other algorithms to train the voice , speech recognition etc. This article serves as a foundation for the same. Hope you enjoyed reading the article. Zipped file attached.

Page copy protected against web site content infringement by Copyscape

About the Author

Rajnilari2015
Full Name: Niladri Biswas (RNA Team)
Member Level: Platinum
Member Status: Member,Microsoft_MVP,MVP
Member Since: 3/17/2015 2:41:06 AM
Country: India
-- Thanks & Regards, RNA Team


Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)