我如何使用与SpeechSynthesizer词库? [英] How do I use a lexicon with SpeechSynthesizer?

查看:265
本文介绍了我如何使用与SpeechSynthesizer词库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行一些文本到语音,我想在词库文件中指定某些特殊的发音。我已经跑 MSDN的AddLexicon例如逐字的,它讲一句话,但它确实的的使用给定的词汇,东西似乎被打破。

I'm performing some text-to-speech and I'd like to specify some special pronunciations in a lexicon file. I have ran MSDN's AddLexicon example verbatim, and it speaks the sentence but it does not use the given lexicon, something appears to be broken.

下面是提供的,例如:

using System;
using Microsoft.Speech.Synthesis;

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

      // Initialize a new instance of the SpeechSynthesizer.
      using (SpeechSynthesizer synth = new SpeechSynthesizer())
      {

        // Configure the audio output. 
        synth.SetOutputToDefaultAudioDevice();

        PromptBuilder builder = new PromptBuilder();
        builder.AppendText("Gimme the whatchamacallit.");

        // Append the lexicon file.
        synth.AddLexicon(new Uri("c:\\test\\whatchamacallit.pls"), "application/pls+xml");

        // Speak the prompt and play back the output file.
        synth.Speak(builder);
      }

      Console.WriteLine();
      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
    }
  }
}

和词库文件:

<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> whatchamacallit </grapheme>
    <phoneme> W S1 AX T CH AX M AX K S2 AA L IH T </phoneme>
  </lexeme>

</lexicon>



控制台打开,文本是口头的,但不使用新的发音。我当然有文件保存到 C:\test\whatchamacallit.pls 为指定的

我'已经开放的和文件位置的尝试变化(例如 @C:\Temp\whatchamacallit.pls @文件:/ //c:\test\whatchamacallit.pls),绝对和相对路径,将其复制到build文件夹等。

I've tried variations of the Uri and file location (e.g. @"C:\Temp\whatchamacallit.pls", @"file:///c:\test\whatchamacallit.pls"), absolute and relative paths, copying it into the build folder, etc.

我跑进程监视器和文件的未访问即可。如果它是一个目录/文件权限问题(它不是),我仍然会看到访问被拒绝的消息,但是我没有登录在基准以外的所有从我的文字编辑器偶尔之一。我看到访问时,我尝试文件 File.OpenRead

I ran Process Monitor and the file is not accessed. If it were a directory/file permission problem (which it isn't) I would still see the access denied messages, however I log no reference at all except the occasional one from my text editor. I do see the file accessed when I try File.OpenRead.

不幸的是使用时没有错误消息垃圾URI。

Unfortunately there are no error messages when using a garbage Uri.

在进一步的调查,我意识到这个例子是从的 Microsoft.Speech.Synthesis ,而我使用的 System.Speech.Synthesis 在这里。但是从我可以告诉他们,除了一些额外的信息和实例,并都指向同规格相同。难道这仍然是这个问题?

On further investigation I realized this example is from Microsoft.Speech.Synthesis, whereas I'm using System.Speech.Synthesis over here. However from what I can tell they are identical except for some additional info and examples and both point to the same specification. Could this still be the problem?

我核实了项目设置为使用正确的.NET Framework 4。

I verified the project is set to use the proper .NET Framework 4.

我比较从MSDN的例子,从引用的规范 例子,以及那些试图彻底但它并没有帮助。考虑到文件似乎并没有被访问,我并不感到惊讶。

I compared the example from MSDN to examples from the referenced spec, as well as trying those outright but it hasn't helped. Considering the file doesn't seem to be accessed I'm not surprised.

(我可以使用 PromptBuilder.AppendTextWithPronunciation 得很好,但它是我的使用情况下,一个贫穷的替代品。)

(I am able to use PromptBuilder.AppendTextWithPronunciation just fine but it's a poor alternative for my use case.)

在MSDN的例子坏了吗?如何使用词库与SpeechSynthesizer?

推荐答案

大量的研究和陷阱后,我可以向你保证,你的假设是完全错误的。
出于某种原因, System.Speech.Synthesis.SpeechSynthesizer.AddLexicon()添加词库到一个内部列表,但根本不使用它。
好像没人使用前它试图与这个错误被忽视了。

After a lot of research and pitfalls I can assure you that your assumption is just plain wrong. For some reason System.Speech.Synthesis.SpeechSynthesizer.AddLexicon() adds the lexicon to an internal list, but doesn't use it at all. Seems like nobody tried using it before and this bug went unnoticed.

Microsoft.Speech.Synthesis.SpeechSynthesizer.AddLexicon()(属于微软的语音SDK),另一方面按预期工作(它通过词汇上到将其解释为发布的COM对象)。

Microsoft.Speech.Synthesis.SpeechSynthesizer.AddLexicon() (which belongs to the Microsoft Speech SDK) on the other hand works as expected (it passes the lexicon on to the COM object which interprets it as advertised).

请参阅以下关于如何安装SDK本指南: http://msdn.microsoft.com/en-us/library/hh362873%28v=office.14%29.aspx

Please refer to this guide on how to install the SDK: http://msdn.microsoft.com/en-us/library/hh362873%28v=office.14%29.aspx

注:


  • 人报告的64位版本导致COM异常(因为库不能正确安装),我在64位的Windows 7证实了这一点机

    • 使用x86版本绕过这个问题

    这篇关于我如何使用与SpeechSynthesizer词库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆