简体   繁体   English

Microsoft.Speech.dll中发生类型'System.FormatException'的未处理的异常

[英]An unhandled exception of type 'System.FormatException' occurred in Microsoft.Speech.dll

I have just tried to use custom pronunciation using a PLS lexicon from thr link http://msdn.microsoft.com/en-us/library/hh378403(v=office.14).aspx . 我刚刚尝试通过thr链接http://msdn.microsoft.com/en-us/library/hh378403(v=office.14).aspx使用PLS词典使用自定义发音。 My .pls file is as following 我的.pls文件如下

Additional information : The lexicon data is invalid or corrupted. 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>

and my c# program is 我的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());
       }
}

but whenever I try to compile it and use it for recognisig "scale" it always shows that "An unhandled exception of type 'System.FormatException' occurred in Microsoft.Speech.dll Additional information: The lexicon data is invalid or corrupted. " 但是,每当我尝试对其进行编译并将其用于Recognisig“ Scale”时,它始终显示“ Microsoft.Speech.dll中发生了'System.FormatException'类型的未处理异常。其他信息:词典数据无效或损坏。”

Although when inline pronunciation is used it works but the pronunciation in external link doesn't seems to work. 尽管使用内联发音时它可以工作,但外部链接中的发音似乎不起作用。 Is there any workaround? 有什么解决方法吗? Any help would be appreciated. 任何帮助,将不胜感激。 Please. 请。

Moving the code above from Microsoft.Speech.Recogonition to System.Speech.Recognition fixes the issue with the format exception above. 将上面的代码从Microsoft.Speech.Recogonition移动到System.Speech.Recognition可解决上述格式异常的问题。

As to why Microsoft.Speech.Recognition is throwing the error, I am not sure. 至于为什么Microsoft.Speech.Recognition引发错误,我不确定。 I do know that the official W3C spec does officially support a lexicon tag in the xml file (although Microsoft has very specific rules as to where the lexicon tag is supposed to be located this appears to be correct): 我确实知道官方W3C规范确实在xml文件中正式支持lexicon标签(尽管Microsoft对于应将lexicon标签放置在何处有非常明确的规则,这似乎是正确的):

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

Lexicon: The grammar format does not address the loading of lexicons or the pronunciation of words referenced by the grammar. 词典:语法格式不能解决词典的加载或语法所引用单词的发音问题。 The W3C Voice Browser Working Group is considering the development of a standard lexicon format. W3C语音浏览器工作组正在考虑开发标准词典格式。 If and when a format is developed appropriate updates will be made to this grammar specification. 如果以及何时开发格式,将对该语法规范进行适当的更新。

The actual spec for the lexicon format is not completed yet: 词典格式的实际规范尚未完成:

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

In summary if Microsofts own example linked here does not work this appears to be a bug. 总而言之,如果此处链接的Microsoft自己的示例不起作用,则似乎是一个错误。 Especially if all you did to fix the format exception is to change from Microsoft.Speech to System.Speech. 尤其是如果您要解决格式异常的所有事情就是将Microsoft.Speech更改为System.Speech。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Speech.dll 中发生类型为“System.FormatException”的未处理异常 - An unhandled exception of type 'System.FormatException' occurred in System.Speech.dll “ mscorlib.dll中发生了&#39;System.FormatException&#39;类型的未处理的异常” - “An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll” mscorlib.dll中发生了&#39;System.FormatException&#39;类型的未处理异常 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll mscorlib.dll中发生了未处理的“System.FormatException”类型异常 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll 发生类型为&#39;System.FormatException&#39;的未处理的异常 - An unhandled exception of type 'System.FormatException' occurred System.Net.Http.dll中发生了未处理的“System.FormatException”类型异常 - An unhandled exception of type 'System.FormatException' occurred in System.Net.Http.dll c# 中的运行时错误 - mscorlib.dll 中发生类型为“System.FormatException”的未处理异常 - Run-time error in c# - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll mscorlib.dll中发生了&#39;System.FormatException&#39;类型的未处理的异常其他信息:输入字符串的格式不正确 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format 尝试解析DateTime时-mscorlib.dll中发生了&#39;System.FormatException&#39;类型的未处理异常 - When trying to parse DateTime - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll 在C#中将十进制转换为十六进制,并出现错误“ mscorlib.dll中发生了&#39;System.FormatException&#39;类型的未处理异常” - decimal to hexadecimal in c# with mistake “An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM