2013-05-05 7 views
1

나는 thr 링크 http://msdn.microsoft.com/en-us/library/hh378403(v=office.14).aspx에서 PLS 어휘집을 사용하여 사용자 지정 발음을 사용하려고했습니다. 내 .pls 파일은 다음과 같습니다.'System.FormatException'형식의 처리되지 않은 예외가 Microsoft.Speech.dll에서 발생했습니다.

Additional information : 어휘 데이터가 유효하지 않거나 손상되었습니다.

<?xml version="1.0" encoding="UTF-8"?> 

<lexicon version="1.0" 
    xmlns="http://www.w3.org/2005/01/pronunciation-lexicon" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon 
    http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd" 
    alphabet="x-microsoft-ups" xml:lang="en-US"> 

    <lexeme> 
     <grapheme> scale </grapheme> 
     <phoneme> S K A L E </phoneme> 
    </lexeme> 
</lexicon> 

and my grammar file is as pronunciation.grxml 


<?xml version="1.0" encoding="UTF-8"?> 
<grammar 
    version="1.0" 
    xml:lang="en-US" 
    root="colors" 
    sapi:alphabet="x-microsoft-ups" 
    xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions" 
    xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0" > 

    <lexicon uri="C:\Users\sony vaio\Documents\Visual Studio 2012\Projects\ConsoleApplication5\ConsoleApplication5\bin\Debug\Blue.pls" type="application/vdn.ms-sapi-lex"/> 

    <rule id="colors" scope="public"> 
     <one-of> 
     <item> scale </item> 
     </one-of> 
    </rule> 

</grammar> 

내 C# 프로그램은

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.IO; 
using System.Xml; 
using Microsoft.Speech; 
using Microsoft.Speech.Recognition; 
using Microsoft.Speech.Recognition.SrgsGrammar; 

namespace ConsoleApplication5 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 

      using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"))) 
      { 

       String currDirPath = Environment.CurrentDirectory; 

       string xmlGrammar = currDirPath + "\\pronunciation.grxml"; 
       string cfgGrammar = currDirPath + "\\pronunciation.cfg"; 
       FileStream fs = new FileStream(cfgGrammar, FileMode.Create); 
       XmlReader reader = XmlReader.Create(xmlGrammar); 

       //compile the grammar *.grxml to *.cfg file. 
       SrgsGrammarCompiler.Compile(reader, (Stream)fs); 
       fs.Close(); 
       Grammar g = new Grammar(cfgGrammar, "colors"); 
       Console.WriteLine(currDirPath+cfgGrammar); 

       recognizer.LoadGrammarAsync(g); 

       // Add a handler for the speech recognized event. 
       recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized); 
       // Configure the input to the speech recognizer. 
       recognizer.SetInputToDefaultAudioDevice(); 

       // Start asynchronous, continuous speech recognition. 
       recognizer.RecognizeAsync(RecognizeMode.Multiple); 

       // Keep the console window open. 
       while (true) 
       { 
        Console.ReadLine(); 
       } 
      } 
     } 

     // speech recognised event handler 

     static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) 
     { 
      string lines = e.Result.Text; 
      Console.WriteLine("Speak loudly"); 
      Console.WriteLine("Recognized text: " + e.Result.Text); 
      Console.WriteLine("semantic value: " + e.Result.Semantics.Value.ToString()); 
     } 
} 

하지만 난 그것을 컴파일하고 recognisig을 위해 그것을 사용하려고 할 때마다 "규모"항상 "그 처리되지 않은 예외 유형의 'System.FormatException을 보여줍니다 'Microsoft.Speech.dll에서 발생했습니다. 추가 정보 : 어휘 데이터가 잘못되었거나 손상되었습니다. "

인라인 발음을 사용하면 외부에서 발음이 가능하지만 링크가 작동하지 않는 것 같습니다. 해결 방법이 있습니까? 어떤 도움을 주시면 감사하겠습니다. 부디.

+1

문제점을 재현하지 못했습니다. 비록 위의 코드를 두 번 편집했지만 나에게 도움이되었습니다. 필자는 Microsoft. *를 System. *으로 대체하고 대신 해당 어셈블리를 참조했습니다. Microsoft.Speech 어셈블리가 설치되어 있지 않습니다. 하지만 당신이보고있는 형식 예외가 발생하지 않습니다. System.Speech 어셈블리에 대해이 문제를 해결하고 여전히 문제가 있는지 확인할 수 있습니까? 또한 txt 편집기에서 열 때 grxml 및 pls 파일을 저장하는 형식은 무엇입니까? UTF-8이 표준입니다. –

+0

안녕하세요. @MattJohnson. 그것은 사람을 움직였습니다. 하지만 그것은 Microsoft. * 어셈블리가이 것을 지원하지 않으며 이것이 system.formatException 또는 lexicon 데이터를 invlaid 또는 오류가 발생시키는 이유 일 수 있습니다. 그리고 네, 내 grxml 및 pls을 저장하는 형식은 UTF-8 표준입니다. 아직도 나는 마이크로 소프트. *가 작동하지 않는 이유를 알고 싶다. – devsda

+0

문제 없습니다. Microsoft.Speech에서 System.Speech로 옮겨서는 안됩니다. W3C 사양을 지원하고 특정 문법 형식 요구 사항을 갖고 있지 않다는 것을 알고 있습니다. –

답변

1

위의 코드를 Microsoft.Speech.Recogonition에서 System.Speech.Recognition으로 이동하면 위의 형식 예외 문제가 해결됩니다.

Microsoft.Speech.Recognition에서 오류가 발생하는 이유에 대해서는 확실하지 않습니다. 나는 (Microsoft는 매우 구체적인 규칙이 있지만 사전 태그가이 올바른 것으로 보인다 위치 할 것으로 예상되는 곳으로) 공식 W3C 사양이 공식적으로 XML 파일의 사전 태그를 지원 않는다는 것을 알고있다 :

http://www.w3.org/TR/speech-grammar/#S4.10

Lexicon : 문법 형식은 어휘집의 로딩이나 문법이 참조하는 단어의 발음을 처리하지 않습니다. W3C 음성 브라우저 워킹 그룹은 표준 사전 형식의 개발을 고려하고 있습니다. 형식이 개발되면이 문법 사양에 대한 적절한 업데이트가 이루어집니다.

어휘 형식의 실제 사양은 아직 완료되지 않은 : 요약

http://www.w3.org/TR/lexicon-reqs/#pronun

는 마이크로 소프트의 자신의 예는 here이이 버그가 나타납니다 작동하지 않는 연결합니다. 특히 형식 예외를 수정 한 경우 Microsoft.Speech에서 System.Speech로 변경해야합니다.

관련 문제