gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:33:25 31 4
gpt4 key购买 nike

我在我的程序中使用 MSDN 的 SpeechRecognitionEngine。问题在于它将背景噪音识别为语音。

例如,如果我打响指、轻敲 table 或移动我的椅子,它就会将其识别为语音。

为什么它会将背景噪音识别为语音。

我打响指的声音和我说“记事本”的声音不一样!!!

这是代码

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");
}
}

}

最佳答案

避免任何过滤算法,您可以检查 Confidence您当前显示的属性。它介于 0.01.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();
}
}

关于c# - SpeechRecognition 将背景噪音识别为语音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28546498/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com