간단한 예제입니다.
유투브 동영상에서는 되는 데 그대로 베껴 쓴 제 code에서는 오류네요.
https://www.youtube.com/watch?v=EgfsGUbhH54
이런 때가 참 혈압이 많이 오르는 때입니다.
[오류메시지] 문법에 사용된 언어가 음성 인식기의 언어와 일치하지 않습니다.
[설치 Assembly] System.Speech
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech;
using System.Speech.Synthesis;
using System.Threading;
using System.Speech.Recognition;
namespace VoiceVocabulary
{
public partial class Form1 : Form
{
SpeechSynthesizer ss = new SpeechSynthesizer();
PromptBuilder pb = new PromptBuilder();
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
Choices clist = new Choices();
public Form1()
{
InitializeComponent();
}
private void btnStart_Click(object sender, EventArgs e)
{
btnStart.Enabled = false;
btnStop.Enabled = true;
clist.Add(new string[] { "Hello", "Good morning", "Welcome", "Thank you" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized += sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
MessageBox.Show("error: " + ex.Message);
}
}
private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
textBox1.Text = textBox1.Text + e.Result.ToString() + Environment.NewLine;
}
[최초 등록일: ]
[최종 수정일: 1/8/2023]