当我说一个两个音节或多个单词时,如何只显示一个输出("已识别,OK")

本文关键字:quot 一个 OK 显示 识别 输出 两个 单词时 | 更新日期: 2023-09-27 18:01:13

我只想让我的程序在听到单词时说"已识别,好!"。有一个或多个音节的单词。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
namespace SpeechRecognitionExample
  {
     public partial class Form1 : Form
          {
           private SpeechRecognitionEngine recognitionEngine;
    public Form1()
    {
        InitializeComponent();
        recognitionEngine = new SpeechRecognitionEngine();
        recognitionEngine.SetInputToDefaultAudioDevice();
        recognitionEngine.SpeechRecognized += (s, args) =>
        {
            foreach (RecognizedWordUnit word in args.Result.Words)
            {
                if (word.Confidence > 0.0f)
                    txtOutput.Text += "Recognized, OK!";
            }
            txtOutput.Text += Environment.NewLine;
        };
        recognitionEngine.LoadGrammar(new DictationGrammar());
    }
    private void btnStart_Click(object sender, EventArgs e)
    {
        recognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
    }
    private void btnStop_Click(object sender, EventArgs e)
    {
        recognitionEngine.RecognizeAsyncStop();
    }
    private void Form1_Load(object sender, EventArgs e)
    {
    }
}

}

请帮帮我。谢谢。因为当我说一个有两三个音节的单词时,它也会显示两三次"已识别,好!"。但如果我说,例如,"START",它只返回1个输出。

当我说一个两个音节或多个单词时,如何只显示一个输出("已识别,OK")

你的意思是,如果有任何单词的话。程序应该说"认可,好吗!"?

如果是,请使用此:

recognitionEngine.SpeechRecognized += (s, args) =>
    {
        if (!args.Result.Words.Any() && word.Confidence <= 0.0f) return;
        txtOutput.Text += "Recognized, OK!";
        txtOutput.Text += Environment.NewLine;
    };