常æ稼åããé³å£°èªèã§ã®èª¤èªè対ç(C#)
é³å£°èªèã®ç²¾åº¦ãä¸ããããã®ä»çµã¿ãä½ã£ã¦è¦ã¾ããã
ãµã³ãã«exe
http://rtilabs.net/files/2011_11_20/DictationFilter.exe
ãµã³ãã«ã½ã¼ã¹
http://rtilabs.net/files/2011_11_20/DictationFilter.zip
éçºç°å¢: VS2010 / C# 4 / win7 64bit ultimate
ãã¼ã ã³ã³ããã¼ã«ã»ã³ã¿ã¼ãªã©ã®é³å£°èªèã§ã¯å¸¸æ稼åãã¦ãããã¨ãæ±ãããã¾ãã
ã¨ã¢ã³ã³å¤ããã®ã«ããã¡ãã¡ãã¿ã³ãæ¼ãã¦ã³ãã³ããçºé³ãããªãã¦ã¢ããªãã¨ã¯ãã¾ããã
ãããªããã¿ã³æ¼ãã¨ãã«åæã«æã§æä½ãããã£ã¦è©±ã§ã
ã§ã常æ稼åãã¦ããããã話ã声ãé»è©±ããã¬ãã®é³ãªã©ã®ãã¤ãºã«ããããã¾ãã
ä¸è¬çã«ç¨ãããããã«ã¼ã«ãã¼ã¹ã®é³å£°èªèã ã¨ãééã£ããããã«ãªããä¸è´ãã¦ãã¾ãã¨ããç¾è±¡ãããã¾ãã
ãã¨ãã°ããã³ã³ãã¥ã¼ã¿ãããã®ã¦ããã¯ãã¨ããã³ãã³ãããã£ãã¨ãã¾ãã
ããã«ããã³ãã¼ãããã®ã¦ããã¯ãã¨çºé³ããã¨ããªããããããã¦ãã¾ãã¾ãã
ããããã«ã¼ã«ãã¼ã¹ã®å®¿å½ã¿ãããªãã®ã§ãä¼¼ã¦ãããã®ã ã£ãããå¤å°è¾ºã§ãããããã¾ãã
ãã®ã¶ããçºé³ãè¯ããªãã¨ãããã¤ãºããã£ã¦ããèãéããå°ãªãã®ããã«ã¼ã«ãã¼ã¹ã®ç¹å¾´ã§ãã
ããä¸æ¹ã®æ¹æ³ã¨ãã¦ãdicticationãã¼ã¹ãããã¾ãã
ããã¯ã«ã¼ã«ã§ã¯ãªããã¡ã¼ã«ãæ¸ãã¨ãã®ããã«ãä¸è¬çã«ææ³ã«åºã¥ãã¦ãæãèªèãã¾ãã
ãã ãããããçã¯åã¾ããä½ããé çæ¼¢ãªçµæãè¿ãã¾ãã
åèªåä½ãªããªãã¨ããªã£ã¦ããæç« ã ã¨æ¬å½ã«ãã¡ããã¡ãã§ãã
(ã¡ãªã¿ã«ãmmmdagent ã§ã¯ãlibjuliusã® dicticationãã¼ã¹ã®èªèãæ¡ç¨ããã¦ããããã§ãmmdagentã®ãããçã®ä½ãã¯ã³ã³ãã¸ãã«åå ãããã¨æã£ã¦ã¾ãã)
ã§ããã¼ã ã³ã³ããã¼ã«ã誤åä½ãã¦ã¯å°ãããã§ãã
é»è©±ããã¦ããããé¨å±ã®é»æ°ãæ¶ããããã¨ã¢ã³ã³ãã¤ããããã¦ããã£ã¦ã¯ãã¡ãªã®ã§ãã(å®è©±w)
ããã§ãã¦ãæ£ããçµæã«ã¯ããããã¦ãããªãã¨å°ãããã§ãã
ã³ã³ãã¥ã¼ã¿ã«ããã¨ãããã¨ããã«ããã§ãã
ã ã£ãããã«ã¼ã«ãã¼ã¹ãã¡ã¤ã³ã¨ãã¦ãããã®ãã¤ãºé¤å»ã« dicticationãã¼ã¹ã®ã¨ã³ã¸ã³ã使ããªããã¨æã£ã¦å®è£ ããã®ãããã§ãã
ã«ã¼ã«ãã¼ã¹ã®é³å£°èªèã¨ããã£ã¯ãã£ã±ã¼ã·ã§ã³ãã¼ã¹ã®é³å£°èªèãåæã«èµ°ããã¾ãã
ã«ã¼ã«ãã¼ã¹ã§ãããããããdicticationãã¼ã¹ã®çµæãè¦ã¦ãdicticationã«ãç¹å®ã®åèªããããå
¥ã£ãããã¿ã¾ãã
ç¹å®ã®åèªãå
¥ã£ã¦ããã°ãæ¡ç¨ãã¦ããã¡ã ã£ããããã失æã¨ãã¾ãã
dicticationãã¼ã¹ã®é³å£°èªèã®çµæã§ãã«ã¼ã«ãã¼ã¹ã®é³å£°èªèã®çµæããã£ã«ã¿ã¼ããæãã§ãã
ãªãã§ãdictication filter ã£ã¦å人çã«ã¯èªãã§ãã¾ãã
ãµã³ãã«ã§ã¯ããã¿ã³ã§ dictication filter ã ON / OFF ã§ããããã«ãã¦ã¿ã¾ããã
ãã³ãã¼ãããã®ã¦ããã¯ããªã©ã¨ä¼¼ãããã§ééã£ãé³å£°èªèã試ãã¦ã¿ã¦ãã ããã
ãã£ã«ã¿ã¼ãæå¹ã®å ´åãééã£ãçµæããããããªãããããã¦ãæ£ããçµæã¯ãããããã¯ãã§ãããã¶ãwã
ã½ã¼ã¹ãè¦ããããããããæ£è¦è¡¨ç¾é¨åã¯åãæã£ãã®ã§ããã£ã¡ã¯ãããã人ã¯ååã®ã¨ã³ããªã¼(正規表現で音声認識)ã試ãã¦ãã ããã
using System; using System.Collections.Generic; using System.Linq; using System.Text; //using System.Speech.Recognition; ããã¯windows7(vistaãï¼)ããéªæªãªä»æ§ã«ãªã£ãã®ã§ä½¿ã£ã¦ã¯ãªã㬠using SpeechLib; //é³å£°èªèãCOMã§å¶å¾¡ãã. (Microsoft Speech Library Object) namespace DictationFilter { class SpeechRecognizer { //é³å£°èªèãªãã¸ã§ã¯ã private SpeechLib.SpInProcRecoContext RecognizerRule = null; private SpeechLib.SpInProcRecoContext RecognizerDictation = null; //è¨èªã¢ãã« private SpeechLib.ISpeechRecoGrammar RecognizerGrammarRule = null; private SpeechLib.ISpeechRecoGrammar RecognizerGrammarDictation = null; //è¨èªã¢ãã«ã®ã«ã¼ã«ã®ãããã¬ãã«ãªãã¸ã§ã¯ã. private SpeechLib.ISpeechGrammarRule RecognizerGrammarRuleGrammarRule = null; //Dictation ã§èªèããæåå. private string DictationString = ""; //å¿ ãããããã¦ããªããã°ãããªãæåå private string MustMatchString = ""; //ä¸ç¶ããããªã²ã¼ã public event _ISpeechRecoContextEvents_StartStreamEventHandler StartStream; //ã¹ããªã¼ã ãéå§ãããæ public event _ISpeechRecoContextEvents_HypothesisEventHandler Hypothesis; //èªèéä¸ã§ãªããæ¾ã£ãæ public event _ISpeechRecoContextEvents_RecognitionEventHandler Recognition; //èªèå®äºæ public event _ISpeechRecoContextEvents_FalseRecognitionEventHandler FalseRecognition; //èªè失ææ public event _ISpeechRecoContextEvents_EndStreamEventHandler EndStream; //ã¹ããªã¼ã çµäºæ public event _ISpeechRecoContextEvents_RecognitionEventHandler DictationRecognition; //Dictationã®èªèå®äºæ public SpeechRecognizer() { //ã«ã¼ã«èªè é³å£°èªèãªãã¸ã§ã¯ãã®çæ this.RecognizerRule = new SpeechLib.SpInProcRecoContext(); this.RecognizerDictation = new SpeechLib.SpInProcRecoContext(); //ãã¤ã¯ããæ¾ã£ã¦ãã this.RecognizerRule.Recognizer.AudioInput = this.CreateMicrofon(); this.RecognizerDictation.Recognizer.AudioInput = this.CreateMicrofon(); //ã¤ãã³ãè¨å®(ä¸ç¶) this.RecognizerRule.Hypothesis += delegate(int streamNumber, object streamPosition, SpeechLib.ISpeechRecoResult result) { this.Hypothesis(streamNumber, streamPosition, result); }; this.RecognizerRule.Recognition += delegate(int streamNumber, object streamPosition, SpeechLib.SpeechRecognitionType srt, SpeechLib.ISpeechRecoResult isrr) { //ããã§Dictationã§ãããããèªãè¦ã¦ã å¿ ãå ¥ã£ã¦ããªããã°ãããªãæååããªããã°æ¡ãã¤ã¶ã. if ( this.MustMatchString.Length >= 1 && this.DictationString.IndexOf(this.MustMatchString) <= -1 ) {//æ¡ãã¤ã¶ã. this.FalseRecognition(streamNumber, streamPosition, isrr); return; } this.Recognition(streamNumber, streamPosition, srt, isrr); }; this.RecognizerRule.StartStream += delegate(int streamNumber, object streamPosition) { this.DictationString = ""; //éå§æã«ååãããããæååãæ¶ã. this.StartStream(streamNumber, streamPosition); }; this.RecognizerRule.FalseRecognition += delegate(int streamNumber, object streamPosition, SpeechLib.ISpeechRecoResult isrr) { this.FalseRecognition(streamNumber, streamPosition, isrr); }; this.RecognizerRule.EndStream += delegate(int streamNumber, object streamPosition, bool streamReleased) { this.EndStream(streamNumber, streamPosition, streamReleased); }; //Dictationã§ãããããæåå. RuleããDictationã®æ¹ããããé ã¯æ©ããããã this.RecognizerDictation.Recognition += delegate(int streamNumber, object streamPosition, SpeechLib.SpeechRecognitionType srt, SpeechLib.ISpeechRecoResult isrr) { //ãããããæååã®è¨é² this.DictationString = isrr.PhraseInfo.GetText(0, -1, true); //ã³ã¼ã«ããã¯ç¨ã®ããªã²ã¼ããå¼ã¶.(ããããããã£ã¦ãããããª) this.DictationRecognition(streamNumber, streamPosition, srt, isrr); }; //è¨èªã¢ãã«ã®ä½æ this.RecognizerGrammarRule = this.RecognizerRule.CreateGrammar(0); this.RecognizerGrammarDictation = this.RecognizerDictation.CreateGrammar(0); } //ãã¤ã¯ããèªã¿åãããããã¤ã¯ç¨ã®ããã¤ã¹ãæå®ãã. // C++ ã 㨠SpCreateDefaultObjectFromCategoryId ãã«ãã¼ããããã ãã©ãC#ã ã¨ãªããã ãªãããã private SpeechLib.SpObjectToken CreateMicrofon() { var ObjectTokenCat = new SpeechLib.SpObjectTokenCategory(); ObjectTokenCat.SetId(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\AudioInput"); var token = new SpeechLib.SpObjectToken(); token.SetId(ObjectTokenCat.Default); return token; } //ã«ã¼ã«ã追å ãã public void SetString(string str) { //ç¾å¨ã®ã«ã¼ã«ããã¹ã¦æ¶ã. this.RecognizerGrammarRule.Reset(0); //è¨èªã¢ãã«ã®ã«ã¼ã«ã®ãããã¬ãã«ãä½æãã. this.RecognizerGrammarRuleGrammarRule = this.RecognizerGrammarRule.Rules.Add("TopLevelRule", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic); //æååã®è¿½å . this.RecognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null,this.MustMatchString + str); //ã«ã¼ã«ãåæ ãããã this.RecognizerGrammarRule.Rules.Commit(); //é³å£°èªèéå§ã(ãããã¬ãã«ã®ãªãã¸ã§ã¯ãã®åå㧠SpeechRuleState.SGDSActive ãæå®ãã.) this.RecognizerGrammarRule.CmdSetRuleState("TopLevelRule", SpeechRuleState.SGDSActive); //Dictationãã¼ã¹ã®é³å£°èªèãã¹ã¿ã¼ã. this.RecognizerGrammarDictation.DictationSetState(SpeechRuleState.SGDSActive); } //çµ¶å¯¾å ¥ã£ã¦ããªãã¨ãããªãæåå public void SetMustMatchString(string str) { this.MustMatchString = str; } } }