【问题标题】:Speech Recognition Engine Breaking Down a Command语音识别引擎分解命令
【发布时间】:2018-09-11 18:12:45
【问题描述】:

我正在编写一个需要识别来自用户的语音命令的 WPF 应用程序。作为语音识别引擎的新手,我不确定如何以最好的方式完成我需要做的事情。申请流程如下:

  • 用户说出关键字来“唤醒”应用程序(例如要求用户说出“Alexa”的 Amazon Echo)
  • 用户说出应用执行的命令(例如“播放‘某位艺术家的某些歌曲’”)

我的问题是,在识别出关键字后,我不确定如何处理我的程序。如果我要在说出关键字后播放用户说的歌曲,我是否需要启动一个新的语音识别器?这是我正在做的一些伪代码:

    private SpeechRecognitionEngine _listen;

    public frmHome()
    {
        InitializeComponent();
        SetupListen();
    }

    private void SetupListen()
    {
        ResetListener();
    }

    private void ResetListener()
    {
        _listen = new SpeechRecognitionEngine();

        Choices exChoices = new Choices();

        exChoices.Add(new String[] { "keyword" });

        GrammarBuilder gb = new GrammarBuilder();
        gb.Append(exChoices);

        Grammar g = new Grammar(gb);

        _listen.LoadGrammar(g);
        _listen.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_speechRecognized);
        _listen.SetInputToDefaultAudioDevice();
        _listen.RecognizeAsync();
    }

    private void sr_speechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        if (e.Result.Text.Equals("keyword"))
        {
            //start listening for the command
        }

        ResetListener();
    }

【问题讨论】:

    标签: c# command speech-recognition voice-recognition speech


    【解决方案1】:

    您可以为启动/停止关键字设置单独的语法,并设置一个标志变量,在说出启动命令时将其设置为 true。

    然后在您的SpeechRecognized 处理程序中,您可以检查标志,然后继续在已识别的文本中搜索命令文本。

    如果您正在寻找一个小的关键字,例如 Alexa,您可以在处理发出的命令之前简单地在已识别的文本中搜索关键字。 Searching the contents of a string.

    希望这篇文章对你有帮助:https://msdn.microsoft.com/en-us/magazine/dn857362.aspx

    【讨论】:

      【解决方案2】:

      只需将_listen.RecognizeAsync(); 替换为_listen.RecognizeAsync(RecognizeMode.Multiple));

      现在您可以发出多个命令了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多