c# – SpeechRecognition将背景噪声识别为语音

前端之家收集整理的这篇文章主要介绍了c# – SpeechRecognition将背景噪声识别为语音前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的程序中使用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,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");
        }
}

}

解决方法

避免使用任何过滤算法,您可以检查当前显示Confidence属性.它介于0.0和1.0之间,其中1非常有信心.我发现0.7效果很好,但你可以搞砸试错.
void sreRecognizedEvent(Object sender,SpeechRecognizedEventArgs e)
{
    if(e.Result.Confidence >= 0.7)
    {
        Console.Write("Reconized ~ " + e.Result.Text + " ~ with confidence " + e.Result.Confidence);
        Console.WriteLine();
    }        
}
原文链接:https://www.f2er.com/csharp/244808.html

猜你在找的C#相关文章