听写不适用于我的WPF应用程序-需要建议

时间:2018-07-02 01:16:07

标签: c# wpf windows voice-recognition dictation

尝试使用自由指示的单词进行语音识别。但这对我不起作用。也许有人可以看看。

从这里开始:

public MainWindow()
    {
        InitializeComponent();

        recognizer = new SpeechRecognitionEngine();

        freeTextDictation();

    }

这是逻辑:

private void freeTextDictation()
    {
        GrammarBuilder startStop = new GrammarBuilder();
        GrammarBuilder dictation = new GrammarBuilder();
        dictation.AppendDictation();

        startStop.Append(new SemanticResultKey("StartDictation", new SemanticResultValue("Start Dictation", true)));
        startStop.Append(new SemanticResultKey("DictationInput", dictation));
        startStop.Append(new SemanticResultKey("StopDictation", new SemanticResultValue("Stop Dictation", false)));

        Grammar grammar = new Grammar(startStop);

        grammar.Enabled = true;
        grammar.Name = " Free-Text Dictation ";
        recognizer.LoadGrammar(grammar);

        recognizer.SetInputToDefaultAudioDevice();

        recognizer.SpeechRecognized += Recognizer_SpeechRecognized;
    }

    private void Recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        //MessageBox.Show(e.Result.Text.ToString());
        Console.WriteLine(e.Result.Text.ToString());
    }

该代码来自Microsoft网站,但我无法对其进行集成以获取输出。 不幸的是,什么都没有发生。

我该怎么办?

0 个答案:

没有答案