如何在字符串变量中复制“语音转文本”文本以进行字符串匹配?

时间:2018-07-21 17:09:26

标签: c#

我是C#的新手,我不确定是否在正确的论坛上写作。我正在构建简单的语音识别程序,该程序将语音命令作为输入,执行语音到文本的翻译,然后搜索与该文本匹配的视频。 我目前将输出存储在文本框中,但我想将其存储在字符串中。

如果有人可以告诉我,我无法编写用于将识别的文本存储到字符串中的正确逻辑代码,该怎么办?这是我的代码...

public partial class Form1 : Form
{
    var ss    = new SpeechSynthesizer();
    var pb    = new PromptBuilder();
    var sre   = new SpeechRecognitionEngine();
    var clist = new Choices();

    private void btnStart_Click(object sender, EventArgs e)
    {
        btnStart.Enabled = false;
        btnStop.Enabled  = true;
        clist.Add(new string[] { "go away", "able", "active", "actual", "afraid", "busy", "casual" });
        Grammar gr = new Grammar(new GrammarBuilder(clist));

        try
        {
            sre.RequestRecognizerUpdate();
            sre.LoadGrammar(gr);
            sre.SpeechRecognized+= sre_SpeechRecognized;
            sre.SetInputToDefaultAudioDevice();
            sre.RecognizeAsync(RecognizeMode.Multiple);
         }
         catch (Exception ex)
         {
            MessageBox.Show(ex.Message, "Error");
         }
    }

    private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) =>
        textContent.Text += e.Result.Text.ToString() + Environment.NewLine;

    private void btnStop_Click(object sender, EventArgs e)
    {
        sre.RecognizeAsyncStop();
        btnStart.Enabled = true;
        btnStop.Enabled = false;
    }
}

0 个答案:

没有答案