C# 语音识别全字典关闭形式

C# 语音识别全字典关闭形式,c#,c#-4.0,speech-recognition,speech,speech-to-text,C#,C# 4.0,Speech Recognition,Speech,Speech To Text,我正试着像贾维斯一样制作语音识别程序,但现在我累坏了。我想做一个写模式。这个模式写下了我说的一切 首先,我想我可以对所有库使用txt文件。我将我的所有txt字典发送到数组,并将字符串数组定义为语法文件,但我不能将其仅用于单词的句子 而txt则发送到字符串以阵列pc堆栈。我不能解释我自己,但我想使用语音到文本库,我想使用所有语法。当我说你好的时候,你是怎么为我写的?它也可以写。我的密码 那是我的IO。它适用于所有字典中的单词。 private ArrayList IoS(int x) {

我正试着像贾维斯一样制作语音识别程序,但现在我累坏了。我想做一个写模式。这个模式写下了我说的一切

首先,我想我可以对所有库使用txt文件。我将我的所有txt字典发送到数组,并将字符串数组定义为语法文件,但我不能将其仅用于单词的句子

而txt则发送到字符串以阵列pc堆栈。我不能解释我自己,但我想使用语音到文本库,我想使用所有语法。当我说你好的时候,你是怎么为我写的?它也可以写。我的密码

那是我的IO。它适用于所有字典中的单词。

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;

}
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;
    }
}
我的语音识别语法代码。

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;

}
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;
    }
}


我是C#编码新手。感谢您所做的一切。

与其在语法中加载大量字符串以使其能够识别许多单词,不如使用一个字符串。这是一种能识别你所说的一切的语法。因此,使用
newdictationgrammar()
作为
LoadGrammar
方法的参数,而不是从大量字符串构建语法。另外,在调用
RecognizeAsync()
之后,不必调用
RecognizeAsync()

我的第二个问题我想关闭所有程序,但我无法关闭我的程序


为此,我需要一些额外的信息。它是控制台应用程序、Windows窗体应用程序还是WPF应用程序?

对于自由形式识别,最好使用不带语法的听写模式。若你们想要单词重复和语法,你们需要使用构造函数重复是的,我试过了,但我的字典库有太多的单词。我想用所有的英语图书馆。当我试图从我的文本程序堆栈中添加库时,我等待了2分钟。首先,感谢您的回复。我的应用程序是Windows窗体应用程序。在我的程序中,我使用以下代码:
private void exitTool_Click(object sender,EventArgs e){this.Close();}
它可以关闭应用程序,但在其他情况下
case“exit”:case“Close program”:this.Close();中断不起作用:(@AyberkHalac)您确定执行了
this.Close();
吗?您可以使用调试器来找出switch语句中发生了什么。
sRecognize.RequestRecognizerUpdate();
sRecognize.LoadGrammar(new DictationGrammar());
sRecognize.SpeechRecognized += sRecognize_SpeechRecognized;
sRecognize.SetInputToDefaultAudioDevice();
sRecognize.RecognizeAsync(RecognizeMode.Multiple);