저는 프로그래밍 초보자입니다. 음성 인식을 사용하여 말하려고했던 것을 보여주는 메시지 상자를 표시하는 간단한 응용 프로그램을 작성하려고합니다. 문제는 처음으로 "hello"라고 말하면서 예를 들어 메시지 상자가 표시되지 않는 경우입니다. 한 번 더 시도하면 올바른 메시지 상자가 재생됩니다. "hello"라고 세 번째로 말하면 2 개의 메시지 상자가 표시됩니다. 네 번째 시간에는 3 개의 메시지 상자 등이 있습니다. 누구든지이 문제를 도울 수 있습니까?이슈 음성 인식 C#
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 Voices
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private SpeechRecognitionEngine sre;
private void Form1_Load(object sender, EventArgs e)
{
sre = new SpeechRecognitionEngine();
sre.SetInputToDefaultAudioDevice();
Choices commands = new Choices();
commands.Add(new string[] { "hello" });
GrammarBuilder gb = new GrammarBuilder();
gb.Append(commands);
Grammar g = new Grammar(gb);
sre.LoadGrammar(g);
sre.RecognizeAsync(RecognizeMode.Multiple);
sre.SpeechRecognized += (s, args) =>
{
foreach (RecognizedPhrase phrase in args.Result.Alternates)
{
if (phrase.Confidence > 0.9f)
sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
}
};
}
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.Text)
{
case "hello":
MessageBox.Show(e.Result.Text);
break;
}
}
}
}
당신이 쓰는 왜'foreach' 루프 :
나는 싶은 것은 다음과 같은 것 같아요? – SLaks