2012-01-17 3 views
1

저는 병렬 포트를 통해 릴레이를 제어하기위한 간단한 음성 인식 응용 프로그램과 함께 작업했으며이 프로그램이 어떻게 작동하는지 기본 프로그램입니다..NET에서 음성 인식이 작동하지 않습니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Speech.Synthesis; 
using Microsoft.Speech.Recognition; 

namespace speechHardware 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      // Create a new SpeechRecognitionEngine instance. 
      var sre = new SpeechRecognitionEngine(); 
      SpeechSynthesizer s = new SpeechSynthesizer(); 
      Console.WriteLine("starting recognizer......."); 
      s.Speak("starting recognizer."); 

      // Create a simple grammar that recognizes "light on", "light off", or "fan on","fan off". 
      Choices colors = new Choices(); 
      Console.WriteLine("option list......."); 
      colors.Add("light on"); 
      colors.Add("light off"); 
      colors.Add("fan on"); 
      colors.Add("fan off"); 

      GrammarBuilder gb = new GrammarBuilder(); 
      gb.Append(colors); 
      Console.WriteLine("starting grammer builder......."); 

      // Create the actual Grammar instance, and then load it into the speech recognizer. 
      Grammar g = new Grammar(gb); 
      sre.LoadGrammar(g); 

      // Register a handler for the SpeechRecognized event. 
      sre.SpeechRecognized += SreSpeechRecognized; 
      //sre.SetInputToWaveFile("C:\Users\Raghavendra\Documents\MATLAB\test.wav"); 
      sre.SetInputToDefaultAudioDevice(); 
      Console.WriteLine("input device recognised.......");   
      s.Speak("input device recognised."); 
     sre.RecognizeAsync(RecognizeMode.Multiple); 
      Console.ReadLine(); 
      Console.WriteLine("stopping recognizer....."); 
      sre.RecognizeAsyncStop(); 

     } 
     static void SreSpeechRecognized(object sender, SpeechRecognizedEventArgs e) 
     { 
      SpeechSynthesizer s = new SpeechSynthesizer(); 
      Console.WriteLine("\nSpeech Recognized: \t{0}" + e.Result.Confidence, e.Result.Text); 

      if (e.Result.Confidence < 0.85) 
       return; 

      switch (e.Result.Text) 
      { 
       case "light on": 
        light(1);      
        s.Speak("the light has been turned on."); 
        break; 
       case "light off": 
        light(0); 
        s.Speak("the light has been turned off."); 
        break; 
       case "fan on": 
        fan(1); 
        s.Speak("the fan has been turned on."); 
        break; 
       case "fan off": 
        fan(0); 
        s.Speak("the fan has been turned off."); 
        break; 
       default: 

        break; 
      } 
     } 
     static void light(int val) 
     { 
      Console.WriteLine("\nSpeech Recognized:light "); 
     } 

     static void fan(int val) 
     { 
      Console.WriteLine("\nSpeech Recognized: fan"); 
     } 


    } 
} 

내 친구 컴퓨터에서는 완벽하게 작동하지만 컴퓨터에서는 입력 내용이 인식되지 않습니다. 우리는 거의 같은 설정을 가지고 있습니다. 마이크도 잘 작동하고 잘못 알고있어.

내가 설치 한 Microsoft 음성 플랫폼 - 소프트웨어 개발 키트 (SDK), 버전 10.2 (86 판) Microsoft 음성 플랫폼 - 서버 런타임 버전 10.2 (86 판)

저를 도와주세요.

+0

신뢰도 값을 기록하십시오. 그것이 무엇을 출력하는지보십시오. – WoLfulus

+0

"우리 둘 다 거의 같은 설정을 가지고 있습니다." 뭐가 달라? 구성을 동일하게 만들면 문제가 사라지는 지 확인할 수 있습니다. 무엇이 다른지 알게되면 문제가 발생하는지 확인할 수 있습니다. – ChrisF

+0

제어판 - 음성 인식에서 "컴퓨터를 더 잘 이해하도록 교육"을 실행 했습니까? –

답변

0

신뢰도를 낮추십시오. 마이크에 잡음이 너무 많거나 음소거가되어있을 수 있습니다. :)

+0

저는 마이크를 정말 가까이에 두었습니다. 그것은 내 친구에게 거의 0.9를주고있었습니다. 또한 F11을 사용하여 디버깅했는데 정상적으로 작동합니다. 나는 무엇이 잘못되었는지 이해하지 못한다. –

1

당신은 sre.RecognizeAsyncStop();를 호출하고 있습니다. 어떤 연설을 알아볼 기회가 있기 전에. 비동기는 비 차단이므로 기억이 인식 될 때까지 기다리지 않습니다. 해당 줄을 제거하면 제대로 작동합니다.

+0

나는 Console.ReadLine()을 지켰다. 성명서는 프로그램이 진행될 때 약간의 정보 만 제공 할 때만 문제가되지 않는다고 생각합니다. –

2

방금 ​​Microsoft.Speech.Recognition을 System.Speech.Recognition으로 바 꾸었습니다.

무엇이 잘못되었는지 이해하지 마십시오.

0

친구가 Windows XP를 실행하고 있고 Vista 또는 7을 실행하고있는 것으로 의심됩니다. Microsoft가 실제로 xp에서 os 패키지의 일부로 음성 인식을 포함 시켰다고 생각합니다. 그것은 Microsoft에서 System으로 include를 변경해야하는 이유에 대한 가능한 대답 일 수 있습니다.

관련 문제