Reputation: 34
I am trying to make speech recognition program like JARVIS but now im stacked. I want to make write mode . This mode writes everything whatever i say.
First of all, I thought i can use txt file for all library.I send my all txt dictionary to Array and I defined String Array as grammer file but i cant use it for sentence only for words.
While txt sent to Strings to array pc stacks. I cant explain myself but i want to use speech to text library and i want to use all grammers for it. When i say hello, how are you write it for me it can write it aswell. my codes
Thats my IO. It's for all dictionary words.
private ArrayList IoS(int x)
{
ArrayList returner = new ArrayList();
string path = "";
string commandDict = @"../../documents/dictionary_C.txt";
string fullDict = @"../../documents/dictionary_F.txt";
if (x == 0)
path = commandDict;
else
if (x == 1)
path = fullDict;
if (IoChecker(path) == false)
Console.Error.WriteLine("ERROR");
using (StreamReader sr = File.OpenText(path))
{
string checker = "";
while ((checker = sr.ReadLine()) != null)
{
returner.Add(checker);
}
}
return returner;
}
My speech recognition grammer code.
private void panel_Load(object sender, EventArgs e)
{
int ListC = 0;
IO io = new IO();
string[] list = new string[io.IoSCaller(ListC).Count];
Choices sList = new Choices();
for (int i = 0; i < io.IoSCaller(ListC).Count; i++)
{
list[i] = (io.IoSCaller(ListC)[i].ToString());
}
sList.Add(list);
Grammar gr = new Grammar(new GrammarBuilder(sList));
try
{
sRecognize.RequestRecognizerUpdate();
sRecognize.LoadGrammar(gr);
sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
sRecognize.SetInputToDefaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);
sRecognize.Recognize();
}
catch
{
return;
}
}
Its working for words but not working for sentence and I cant save all sentece. What can i do for it i want to use all dictionary and serial input not word by word.
My second Question I want to close all program but I cannot close my program. I am using this codes but non of them close my program. I cant close my program inside of my code please help me.
System.Environment.Exit(0);
Environment.Exit(0);
Application.Exit();
System.Diagnostics.Process[] procs = System.Diagnostics.Process.GetProcessesByName("vshost32");
foreach (System.Diagnostics.Process proc in procs)
{
proc.CloseMainWindow();
}
I'm new for C# coding. Thanks for everything.
Upvotes: 1
Views: 2226
Reputation: 6390
Instead of loading a lot of strings into your grammar to make it recognize many words, you better use a DictationGrammar
. This is a grammar that recognizes everything you say. So instead of building your grammar from a lot of strings, use new DictationGrammar()
as parameter for the LoadGrammar
method. Also, it's not necessary to call Recognize()
after you call RecognizeAsync()
.
sRecognize.RequestRecognizerUpdate();
sRecognize.LoadGrammar(new DictationGrammar());
sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
sRecognize.SetInputToDefaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);
My second Question I want to close all program but I cannot close my program.
For this, I need some extra information. Is it a Console Application, Windows Forms Application or WPF application?
Upvotes: 2