Speech-to-Text and Text-to-Speech conversion using .NET
With System.Speech reference we can work on Speech-to-Text and Text-to-Speech conversion in .NET. So first step while working on this simple application is to add reference to this namespace as follows
Note: For recognizing voice, i.e. Speech-to-Text add System.Speech.Recognition Namespace and for Speak functionality i.e. Text-to-Speech add System.Speech.Synthesis Namespace
Let’s first work on Speech recognition be creating a simple console application.
Here we have to add System.Speech.Recognition namespace in our console application.
After that write following code in main()-
using (SpeechRecognitionEngine rec = new SpeechRecognitionEngine(new CultureInfo("en-US")))
{
rec.LoadGrammar(new DictationGrammar());
rec.SpeechRecognized += rec_SpeechRecognized;
rec.SetInputToDefaultAudioDevice();
rec.RecognizeAsync(RecognizeMode.Multiple);
while (true)
{
Console.ReadLine();
}
}
Event Handling
static void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine(e.Result.Text);
}
For additional information please visit link https://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine(v=vs.110).aspx
Similarly create another console application for Text-to-Speech functionality and here we have to add System.Speech.Synthesis namespace. After that add following code in Main()
SpeechSynthesizer syn = new SpeechSynthesizer();
syn.Speak("this is test speaking application");
if (syn != null)
{
syn.Dispose();
}
Console.ReadLine();
We can work on several variation in these both the application to understand more in details about System.Speech reference.
No comments:
Post a Comment