Thinking Different




이 프로그램 소스는 윈도우 SAPI Library를 활용한 음성인식 소스로써, 간단히 grammer 파일에 명령 워드(word)를 통해서 실행된 명령어를 해석하여 TTS answer 및 몇몇의 정해진 프로그램을 구동하는 기능을 구현한 소스입니다.


 

 필수 설치 프로그램


 Microsoft Speech Platform - Runtime (Version 11)

 http://www.microsoft.com/en-us/download/details.aspx?id=27225



 Microsoft Speech Platform - Software Development Kit (SDK) (Version 11)

 http://www.microsoft.com/en-us/download/details.aspx?id=27226



 Microsoft Speech Platform - Runtime Languages (Version 11)

 http://www.microsoft.com/en-us/download/details.aspx?id=27224


 한글 음성인식: MSSpeech_SR_ko-KR_TELE.msi

 한글 TTS: MSSpeech_TTS_ko-KR_Heami.msi






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
 
using Microsoft.Speech.Recognition;
using Microsoft.Speech.Synthesis;
 
 
namespace SR_Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
 
            initRS();
            initTTS();
        }
 
        public void initRS()
        {
            try
            {
                SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new CultureInfo("ko-KR"));
 
                Grammar g = new Grammar("input.xml");
                sre.LoadGrammar(g);
                
                sre.SpeechRecognized += new EventHandler(sre_SpeechRecognized);
                sre.SetInputToDefaultAudioDevice();
                sre.RecognizeAsync(RecognizeMode.Multiple);
            }
            catch (Exception e)
            {
                label1.Text = "init RS Error : " + e.ToString();
            }
        }
 
        SpeechSynthesizer tts;
 
        public void initTTS()
        {
            try 
            {
                tts = new SpeechSynthesizer();
                tts.SelectVoice("Microsoft Server Speech Text to Speech Voice (ko-KR, Heami)");
                tts.SetOutputToDefaultAudioDevice();
                tts.Volume = 100;
            }
            catch(Exception e)
            {
                label1.Text = "init TTS Error : " + e.ToString();
            }
        }
 
        void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            label1.Text = e.Result.Text;
 
            switch(e.Result.Text)
            {
                case "컴퓨터":
                    tts.SpeakAsync("네 컴퓨터입니다");
                    break;
 
                case "안녕":
                    tts.SpeakAsync("반갑습니다 음성인식 테스터입니다");
                    break;
 
                case "종료":
                    {
                        tts.Speak("프로그램을 종료합니다");
                        Application.Exit();
                        break;
                    }
 
                case "계산기":
                    {
                        tts.SpeakAsync("계산기를 실행합니다");
                        doProgram("c:\\windows\\system32\\calc.exe", "");
                        break;
                    }
               
                case "메모장":
                    {
                        tts.SpeakAsync("메모장을 실행합니다");
                        doProgram("c:\\windows\\system32\\notepad.exe", "");
                        break;
                    }
 
                case "콘솔":
                    {
                        tts.SpeakAsync("콘솔을 실행합니다");
                        doProgram("c:\\windows\\system32\\cmd.exe", "");
                        break;
                    }
 
                case "그림판":
                    {
                        tts.SpeakAsync("그림판을 실행합니다");
                        doProgram("c:\\windows\\system32\\mspaint.exe", "");
                        break;
                    }
 
                case "계산기 닫기":
                    {
                        tts.SpeakAsync("계산기를 종료합니다");
                        closeProcess("calc");
                        break;
                    }
            }
        }
 
        // 프로세스 실행
        private static void doProgram(string filename, string arg)
        {
            ProcessStartInfo psi;
            if(arg.Length != 0)
                psi = new ProcessStartInfo(filename, arg);
            else
                psi = new ProcessStartInfo(filename);
            Process.Start(psi);
        }
 
        // 프로세스 종료
        private static void closeProcess(string filename)
        {
            Process[] myProcesses;
            // Returns array containing all instances of Notepad.
            myProcesses = Process.GetProcessesByName(filename);
            foreach (Process myProcess in myProcesses)
            {
                myProcess.CloseMainWindow();
            }
        }
    }
}






SR_Test.zip