여기에 다음 코드받아쓰기 문법 VS 사용자 정의 문법
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Windows.Forms;
using System.IO;
namespace US_Speech_Recognizer
{
public class RecognizeSpeech
{
private SpeechRecognitionEngine sEngine; //Speech recognition engine
private SpeechSynthesizer sSpeak; //Speech synthesizer
string text3 = "";
public RecognizeSpeech()
{
//Make the recognizer ready
sEngine = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
//Load grammar
Choices sentences = new Choices();
sentences.Add(new string[] { "I am hungry" });
GrammarBuilder gBuilder = new GrammarBuilder(sentences);
Grammar g = new Grammar(gBuilder);
sEngine.LoadGrammar(g);
//Add a handler
sEngine.SpeechRecognized +=new EventHandler<SpeechRecognizedEventArgs>(sEngine_SpeechRecognized);
sSpeak = new SpeechSynthesizer();
sSpeak.Rate = -2;
//Computer speaks the words to get the phones
Stream stream = new MemoryStream();
sSpeak.SetOutputToWaveStream(stream);
sSpeak.Speak("I was hungry");
stream.Position = 0;
sSpeak.SetOutputToNull();
//Configure the recognizer to stream
sEngine.SetInputToWaveStream(stream);
sEngine.RecognizeAsync(RecognizeMode.Single);
}
//Start the speech recognition task
private void sEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
string text = "";
if (e.Result.Text == "I am hungry")
{
foreach (RecognizedWordUnit wordUnit in e.Result.Words)
{
text = text + wordUnit.Pronunciation + "\n";
}
MessageBox.Show(e.Result.Text + "\n" + text);
}
}
}
}
에서 참조하시기 바랍니다, 문법은 I am hungry
하지만 컴퓨터가 I was hungry
말하도록 요청한다. 그러나 사건은 인정 사건이 해고되고 텍스트가 정확히 I am hungry
!!와 같다고 말합니다. 출력 상자에서 음소를 확인할 수 있습니다!
이를 방지 할 수있는 유일한 방법은 내가 정의 문법을 제공 생각한 DictationGrammar
로드되는 모든 필요하지 듣고에서 응용 프로그램을 제한하는 가장 좋은 방법이지만, 사용자 정의 문법 실패처럼 보인다!
제 질문은이를 피할 수있는 방법이 있습니까? 왜 이런 일이 일어나는거야?
도움을 주시면 대단히 감사하겠습니다. 감사.