CHOU
Speech SDK 5.1을 이용한 음성인식 프로그램 본문
다음주에 있는 청소년 과학관 행사를 위해 음성인식을 통해서 로봇을 제어하는 것을 구현하고 있는데,
Speech SDK 5.1과 C#을 이용하였습니다.
간단하게 구현이 가능해서 테스트를 해보는데 windows XP 버전에서는 동작을 안하고, windows7에서는
동작이 잘되어서 왜그런가 구글신께 여쭤보았더니, 역시나 꽤나 이슈가 되고 있는 문제였습니다.
음성인식을 하려고 windows7으로 업그레이드를 해야하나.. 고민입니다.
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.Threading;
using System.Speech;
using System.Speech.Synthesis;
using System.Speech.Recognition;
namespace VoiceRecognition
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//speech
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
//create the recognition engine
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
//create a new GrammerBuilder to specify which commands we want to use
GrammarBuilder grammarBuilder = new GrammarBuilder();
private void button1_Click(object sender, EventArgs e)
{
//append all the choice we want for commands.
//we want to be able to one, two, three..it's only test..
grammarBuilder.Append(new Choices("one", "two", "three"));
//create the Grammar from the grammarBuilder
Grammar customGrammar = new Grammar(grammarBuilder);
//unload any grammars from the recognition engine
sre.UnloadAllGrammars();
//load out new grammar
sre.LoadGrammar(customGrammar);
Thread t1 = new Thread(delegate()
{
//set our recognition engine to use the default audio device
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
});
t1.Start();
//add an event handler so we get events whenever the engine recognizes spoken commands
sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
//set the recognition engine to keep running after recognition a command.
//if we had used RecognizeMode.single, the engine would quite listening after
//the first recognized command.
//sre.RecognizeAsync(RecognizeMode.Multiple);
}
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
//simple check to see what the result of the recognition was
switch (e.Result.Text)
{
//check for the count
//we have to make sure we aren't in checking mode first.
case "one":
textBox1.Text = "one";
break;
case "two":
textBox1.Text = "two";
break;
case "three":
textBox1.Text = "three";
break;
}
}
구현하는 부분은 그렇게 어렵지 않은데, 문제는 마이크에 대한 응답속도가 생각보다 느리고,
잡음에 강인하지 않으며, windows vista이상에서 원활이 작동한다는 것입니다.