我只想让我的节目说“认可,好!”如果它听到的话。包含一个或多个音节词的单词。
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个输出。
答案 0 :(得分:0)
你的意思是,如果有任何字眼。该程序应该说"认可,好!"?
如果是这样,请使用:
recognitionEngine.SpeechRecognized += (s, args) =>
{
if (!args.Result.Words.Any() && word.Confidence <= 0.0f) return;
txtOutput.Text += "Recognized, OK!";
txtOutput.Text += Environment.NewLine;
};