我在我的程序中使用MSDN的SpeechRecognitionEngine
。问题是它将背景噪音识别为语音。
例如,如果我弹指头、敲桌子或移动椅子,它会将这些声音识别为语音。
为什么它会将背景噪音识别为语音呢?
我弹指头的声音和我说“记事本”的声音不一样啊!
以下是代码:
using System;
using System.Threading;
using System.Speech;
using System.Speech.Synthesis;
using System.Speech.Recognition;
namespace SpeachTest
{
public class MainClass
{
static void Main()
{
MainClass main = new MainClass();
SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
Choices choiceList = new Choices();
choiceList.Add(new string[]{"Open", "Close", "Then", "Volume", "Up", "Firefox", "Notepad", "Steam","turn", "the", "now" } );
GrammarBuilder builder = new GrammarBuilder();
builder.Append(choiceList);
Grammar grammar = new Grammar(new GrammarBuilder(builder,0, 10) );
sre.SpeechRecognized += main.sreRecognizedEvent;
sre.SpeechDetected += main.sreDetectEvent;
sre.SpeechRecognitionRejected += main.sreRejectEvent;
sre.RecognizeCompleted += main.sreCompleteEvent;
sre.InitialSilenceTimeout = TimeSpan.FromSeconds(0);
sre.BabbleTimeout = TimeSpan.FromSeconds(0);
sre.EndSilenceTimeout = TimeSpan.FromSeconds(0);
sre.EndSilenceTimeoutAmbiguous = TimeSpan.FromSeconds(0);
sre.SetInputToDefaultAudioDevice();
sre.LoadGrammar(grammar);
while(true){
sre.Recognize();
}
}
void sreRecognizedEvent(Object sender, SpeechRecognizedEventArgs e){
Console.Write("Reconized ~ " + e.Result.Text + " ~ with confidence " + e.Result.Confidence);
Console.WriteLine();
}
void sreDetectEvent(Object sender, SpeechDetectedEventArgs e){
Console.WriteLine("Detected some type of input");
}
void sreRejectEvent(Object sender, SpeechRecognitionRejectedEventArgs e){
Console.WriteLine("Rejected Input ~ " + e.Result.Text) ;
}
void sreCompleteEvent(Object sender, System.Speech.Recognition.RecognizeCompletedEventArgs e){
Console.WriteLine("Completed Recongnization");
}
}
}
BabbleTimeout
设为0?我没有检查其他的,但是对于BabbleTimeout
来说,0 是默认值。如果设置几秒钟以上的值会发生什么? - Mehraban