2012-05-16 4 views
6

나는 인식을위한 프로젝트를 가지고 있습니다. 그것은 작동하지만 다른 클래스에서 메서드를이 프로젝트를 사용하는 방법 클래스와 호출하는 경우 I 라인에 예외에 문제가 :Kinect의 음성 인식

sre = new SpeechRecognitionEngine(ri.Id); 

오류 존재 :

필요한 없음 인식기 ID가 발견되었습니다.

코드 :

KinectAudioSource source = kinectSensor.AudioSource; 
source.EchoCancellationMode = EchoCancellationMode.None; // No AEC for this sample 
source.AutomaticGainControlEnabled = false; // Important to turn this off for speech recognition 
// source.SystemMode = SystemMode.OptibeamArrayOnly; 
speechRecognizer = CreateSpeechRecognizer(); 

using (Stream s = source.Start()) 
{ 
    speechRecognizer.SetInputToAudioStream(s, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null)); 
    Console.WriteLine("Recognizing speech. Say: 'purple', 'green' or 'blue'. Press ENTER to stop"); 
    speechRecognizer.RecognizeAsync(RecognizeMode.Multiple); 
    Console.ReadLine(); 
    Console.WriteLine("Stopping recognizer ..."); 
    speechRecognizer.RecognizeAsyncStop(); 
    } 

private static SpeechRecognitionEngine CreateSpeechRecognizer() 
{ 
    RecognizerInfo ri = GetKinectRecognizer(); 

    SpeechRecognitionEngine sre; 
    //if (ri == null) return 0; 
    sre = new SpeechRecognitionEngine(ri.Id); 
    var colors = new Choices(); 
    colors.Add("red"); 
    colors.Add("green"); 
    colors.Add("blue"); 
    var gb = new GrammarBuilder { Culture = ri.Culture }; 
    gb.Append(colors); 

    // Create the actual Grammar instance, and then load it into the speech recognizer. 
    var g = new Grammar(gb); 
    sre.LoadGrammar(g); 
    sre.SpeechRecognized += SreSpeechRecognized; 
    sre.SpeechHypothesized += SreSpeechHypothesized; 
    sre.SpeechRecognitionRejected += SreSpeechRecognitionRejected; 
    return sre; 
    } 
private static RecognizerInfo GetKinectRecognizer() 
    { 
    Func<RecognizerInfo, bool> matchingFunc = r => 
    { 
     string value; 
     r.AdditionalInfo.TryGetValue("Kinect", out value); 
     return "True".Equals(value, StringComparison.InvariantCultureIgnoreCase) && "en-US".Equals(r.Culture.Name, StringComparison.InvariantCultureIgnoreCase); 
     }; 
     return SpeechRecognitionEngine.InstalledRecognizers().Where(matchingFunc).FirstOrDefault(); 
    } 
+3

ID를 디버그하십시오. 값이 올바른지 확인하십시오. – Fixus

+0

Kinect를 지원하기 위해 필요한 32 비트 음성 엔진을 설치했는지 확인하십시오. 이 페이지에 나열된 전제 조건을 따르십시오. http://channel9.msdn.com/coding4fun/kinect/Introduction-to-Kinect-Speech-Recognition –

+0

플랫폼 대상은 무엇입니까? – animaonline

답변

4

내가 당신 GetKinectRecognizer() 메소드가 올바르지 않은 생각합니다.

TryGetValue()가 발견되지 않고 out 매개 변수로 발견 된 값을 반환하는 경우 부울을 반환하지 않습니까? TryGetvalue()에서 반환 된 부울 값으로 아무 것도하지 않습니다.

AdditionalInfo 사전에 키가 "Kinect"이고 문자열이 "True"또는 "False"가 되길 기대합니까? 그것이 당신이 찾는 코드입니다.

이 코드는 사용자가 가리킬 수있는 예제를 기반으로합니다. 필자는 matchingFunc에서 테스트 한 내용을 실제로 따르지 않습니다. TryGetvalue의 반환 값을 무시하고 문자열 값이 "True"인 AdditionalInfo 키와 문화권이 "en-US"인 인식기를 찾고 있습니다.

SpeechRecognitionEngine.InstalledRecognizers()의 내용을 덤프하고 포함 된 것으로 생각하는 내용이 포함되어 있는지 확인하십시오. 이것은 오래된 학교,하지만 유용 : 나는 키 넥트 SDK를 설치하지 않은

foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers()) 
{ 
    Debug.WriteLine(String.Format("Id={0}, Name={1}, Description={2}, Culture={3}", ri.Id, ri.Name, ri.Description, ri.Culture)); 
    foreach(string key in ri.AdditionalInfo.Keys) 
    { 
     Debug.WriteLine(string.Format("{0} = {1}", key, ri.AdditionalInfo[key])); 
    } 
    Debug.WriteLine("-"); 
} 

,하지만 내 윈도우 7 컴퓨터에 그것을 보여줍니다

Id=MS-1033-80-DESK, Name=MS-1033-80-DESK, Description=Microsoft Speech Recognizer 8.0 for Windows (English - US), Culture=en-US 
VendorPreferred = 
CommandAndControl = 
Version = 8.0 
Language = 409;9 
Desktop = 
SupportedLocales = 409;1009;3409;9 
AudioFormats = 16;18;20;22;45;53;{6F50E21C-E30E-4B50-95E9-21E8F23D15BD} 
SpeakingStyle = Discrete;Continuous 
WildcardInCFG = Anywhere;Trailing 
Dictation = 
Hypotheses = 
Alternates = CC;Dictation 
windowsV6compatible = 
Name = MS-1033-80-DESK 
DictationInCFG = Anywhere;Trailing 
UPSPhoneSet = 
WordSequences = Anywhere;Trailing 
Vendor = Microsoft 
- 
Id=MS-2057-80-DESK, Name=MS-2057-80-DESK, Description=Microsoft Speech Recognizer 8.0 for Windows (English - UK), Culture=en-GB 
= 
VendorPreferred = 
CommandAndControl = 
Version = 8.0 
Language = 809 
Desktop = 
SupportedLocales = 809;C09;1409;1809;1C09;2009;2409;2809;2C09;3009;4009;4409;4809;9 
AudioFormats = 16;18;20;22;45;53;{6F50E21C-E30E-4B50-95E9-21E8F23D15BD} 
SpeakingStyle = Discrete;Continuous 
WildcardInCFG = Anywhere;Trailing 
Dictation = 
Hypotheses = 
Alternates = CC;Dictation 
windowsV6compatible = 
Name = MS-2057-80-DESK 
DictationInCFG = Anywhere;Trailing 
UPSPhoneSet = 
WordSequences = Anywhere;Trailing 
Vendor = Microsoft 
- 
- 

이 값은 당신이에서 찾고 있는지 확인 AdditionalInfo 사전이 실제로 있습니다. 그런 다음 matchingFunc를 조작하여 확인하십시오.

+0

+51, 이것은 나를 위해 일했습니다! –

3

시도해보십시오. 그것은 나를 위해 작동합니다.

private static RecognizerInfo GetKinectRecognizer() 
     { 
      foreach (RecognizerInfo recognizer in SpeechRecognitionEngine.InstalledRecognizers()) 
      { 
       System.Diagnostics.Debug.Write(recognizer.Culture.Name+"\n\n"); 
       //string value; 
       //recognizer.AdditionalInfo.TryGetValue("Kinect",out value); 
       if ("en-US".Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase)) 
       { 
        return recognizer; 
       } 

      } 

      return null; 
     } 
+0

나를 위해 일했습니다. 기록을 위해 방금 Microsoft 음성 플랫폼 SDK v11.0, Microsoft 음성 플랫폼 런타임 v11.0 및 재배포 가능 언어 팩 v11.0 (__in이 주문 _)의 64x 버전을 설치했습니다. [여기] (https://msdn.microsoft.com/en-us/library/office/hh361572(v=office.14) .aspx)에서 다운로드 할 수 있습니다. – Thoth