Good morning. I have a console application made in C # for speech recognition with the class System.Speech.Recognition
that recognizes the audio and writes it in a document called tub.txt. Here the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Speech.Recognition;
using System.IO;
namespace VoiceRecognitionForIvernAppConsole
{
class Program
{
static void Main(string[] args)
{
SpeechRecognitionEngine listen = new SpeechRecognitionEngine();
listen.SetInputToDefaultAudioDevice();
listen.LoadGrammar(new DictationGrammar());
listen.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(reader);
listen.RecognizeAsync(RecognizeMode.Multiple);
void reader(object sender, SpeechRecognizedEventArgs e)
{
TextWriter file;
file = new StreamWriter("tub.txt");
foreach (RecognizedWordUnit word in e.Result.Words)
{
file.WriteLine(word.Text + " ");
Console.Write(word.Text + " ");
}
file.Close();
}
Console.ReadKey();
}
}
}
My problem is that when I finish speaking I must press a key obviously the command Console.ReadKey (); Otherwise, the application opens and closes immediately. I just want the app not to close until I hear something, a word or a sentence, then if it can be closed, without having to press a key. If not wait, listen, write in the document and close later. Nor would I put something with an if (word.Text.Equals ("quit")) because I just want to say maybe "Hello world" and then close. I read the documentation but I did not see a utility like that. Or I do not know if I'll be overlooking it. If someone has an idea, I thank them in advance.