나는 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에서 발생했습니다. 추가 정보 : 어휘 데이터가 잘못되었거나 손상되었습니다. "
인라인 발음을 사용하면 외부에서 발음이 가능하지만 링크가 작동하지 않는 것 같습니다. 해결 방법이 있습니까? 어떤 도움을 주시면 감사하겠습니다. 부디.
문제점을 재현하지 못했습니다. 비록 위의 코드를 두 번 편집했지만 나에게 도움이되었습니다. 필자는 Microsoft. *를 System. *으로 대체하고 대신 해당 어셈블리를 참조했습니다. Microsoft.Speech 어셈블리가 설치되어 있지 않습니다. 하지만 당신이보고있는 형식 예외가 발생하지 않습니다. System.Speech 어셈블리에 대해이 문제를 해결하고 여전히 문제가 있는지 확인할 수 있습니까? 또한 txt 편집기에서 열 때 grxml 및 pls 파일을 저장하는 형식은 무엇입니까? UTF-8이 표준입니다. –
안녕하세요. @MattJohnson. 그것은 사람을 움직였습니다. 하지만 그것은 Microsoft. * 어셈블리가이 것을 지원하지 않으며 이것이 system.formatException 또는 lexicon 데이터를 invlaid 또는 오류가 발생시키는 이유 일 수 있습니다. 그리고 네, 내 grxml 및 pls을 저장하는 형식은 UTF-8 표준입니다. 아직도 나는 마이크로 소프트. *가 작동하지 않는 이유를 알고 싶다. – devsda
문제 없습니다. Microsoft.Speech에서 System.Speech로 옮겨서는 안됩니다. W3C 사양을 지원하고 특정 문법 형식 요구 사항을 갖고 있지 않다는 것을 알고 있습니다. –