语音识别引擎打破命令

问题描述 投票:1回答:2

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

  • 用户说出一个关键词'唤醒'应用程序(来自Amazon Echo,要求用户说'Alexa')
  • 用户说出要执行的应用程序的命令(例如“播放某些艺术家的某些歌曲”)

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

    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
2个回答
0
投票

您可以为开始/停止关键字使用单独的语法,并且具有一个标志变量,当使用start命令时,该变量设置为true。

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

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

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


0
投票

_listen.RecognizeAsync();替换_listen.RecognizeAsync(RecognizeMode.Multiple));

现在您可以提供多个命令。

© www.soinside.com 2019 - 2024. All rights reserved.