0
我只想讓我的程序說「已識別,好!如果它聽到的話。有一個或多個音節詞的詞。當我說一個雙音節詞或更多時,如何只顯示一個輸出(「識別,OK」)
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)
{
}
}
}
請幫助我。謝謝。因爲當我說一個有兩個或三個音節的詞時,它會顯示「已識別,好!」兩次或三次。但是,如果我說,例如,「開始」它只返回1輸出。
所以我會忽略這個詞有信心嗎? – shannen 2013-02-27 03:16:27
我剛剛編輯了代碼,請再試一次。 – 2013-02-27 03:21:43
你剛剛複製 - 粘貼其他代碼? 'args.Result.Words.Any()' – 2013-02-27 03:34:41