C#语音识别解析用户说的值

时间:2017-11-04 19:01:23

标签: c# speech-recognition

我想制作一个程序,从网站上基本检查机场天气。 我希望我的代码听一个命令(女巫是检查天气),然后用户将通过ICAO告诉程序在哪里检查天气(4个字母代码用于机场,例如EHAM =阿姆斯特丹史基浦) 我坚持如何使识别引擎听取用户所说的内容,将其从拼音字母转换为普通字母,并将4个字母组合成网址以获取天气信息。一旦我有4个字母,我知道如何将其实现到URL中。

我有什么安慰:`

using System.Speech.Recognition;

namespace Voice_Reco_Test
{
    public partial class Form1 : Form
    {
        SpeechRecognitionEngine RecEngine = new SpeechRecognitionEngine();

    public Form1()
    {
        InitializeComponent();



    }

    private void Form1_Load(object sender, EventArgs e)
    {


        Choices commands = new Choices();
        commands.Add(new string[] { "check metar for ","alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliet", "kilo", "lima", "mike", "november", "oscar", "papa", "quebec", "romeo", "sierra", "tango", "uniform", "victor", "whiskey", "x-ray", "yankee", "zulu" });

        GrammarBuilder gBuilder = new GrammarBuilder();
        gBuilder.Append(commands);

        Grammar grammar = new Grammar(gBuilder);

        RecEngine.LoadGrammarAsync(grammar);

        RecEngine.SetInputToDefaultAudioDevice();
        RecEngine.SpeechRecognized += RecEngine_SpeechRecognized;


    }

    private void RecEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
       switch (e.Result.Text)
        {

//此处用户说出4个拼音字母以及程序需要复制并插入URL的字母                 案例"检查metar为" :

                break;

        }
    }

    private void BtnEnable_Click(object sender, EventArgs e)
    {
        RecEngine.RecognizeAsync(RecognizeMode.Multiple);
        BtnDisable.Enabled = true;

    }

    private void BtnDisable_Click(object sender, EventArgs e)
    {
        RecEngine.RecognizeAsyncStop();
        BtnDisable.Enabled = false;
    }
}

} `

编辑:编辑代码并删除了4个不同的选择

0 个答案:

没有答案