【问题标题】:The right way to use SSML with Web Speech API将 SSML 与 Web Speech API 一起使用的正确方法
【发布时间】:2014-03-24 01:09:21
【问题描述】:

Web Speech API specification 说:

文本属性
该属性指定要合成的文本和 为这句话说话。这可以是纯文本或 完整、格式良好的 SSML 文档。用于语音合成引擎 不支持 SSML 或仅支持某些标签的用户 代理或语音引擎必须去除它们不支持的标签 并说出文字。

它没有提供将text 与 SSML 文档一起使用的示例。

我在 Chrome 33 中尝试了以下操作:

var msg = new SpeechSynthesisUtterance();
msg.text = '<?xml version="1.0"?>\r\n<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US">ABCD</speak>';
speechSynthesis.speak(msg);

它不起作用——声音试图叙述 XML 标签。此代码有效吗?
我必须提供XMLDocument 对象吗?

我试图了解 Chrome 是否违反规范(应将其报告为错误),或者我的代码是否无效。

【问题讨论】:

  • 你解决过这个问题吗?我在 SSML 和 chrome 上能找到的最接近的东西是 Chrome 插件语音合成的文档developer.chrome.com/extensions/tts
  • 你也在使用 Linux。因为看来那里可能有问题code.google.com/p/chromium/issues/detail?id=88072
  • @ElDog 我发现的只是那个错误(我在那里发表了评论)——顺便说一句,我阅读描述的方式也没有在 Mac/Win 中实现。
  • 从那个 bug 线程和其他人看来,这个 Chrome API 根本不支持 SSML,看起来它对任何人来说都不是高优先级。希望加点时间,让语音合成的响应速度更快。
  • @AndreyShchekin 啊,是的,我的错,它似乎也是 Mac/Win。现在回到我的 TTS 服务器端,需要 SSML 来推销我的歌声技巧。

标签: google-chrome speech-synthesis webspeech-api


【解决方案1】:

我已经对此进行了测试,XML 解析在 Windows 中似乎可以正常工作,但在 MacOS 中却无法正常工作。

【讨论】:

  • 我只是想让 XML 解析在 Windows 10 中工作,但在 firefox、chrome、edge 中没有成功。非常感谢任何指向工作示例的指针。
【解决方案2】:

目前在 Chromium 中存在与此问题相关的错误。

  • 88072:扩展TTS API平台实现需要支持SSML
  • 428902: speechSynthesis.speak() 不会去除无法识别的标签截至 2016 年 9 月,此错误已在 Chrome 中修复。

【讨论】:

  • 而 428902 回归了:/ 它还在这里。
  • 该错误发生在 Windows 中,但不是 MacOS。
【解决方案3】:

在 Chrome 46 中,当语言设置为 en 时,在 Windows 上,XML 被正确解释为 XML 文档;但是,我没有看到标签实际上在做任何事情的证据。我听说此 SSML 的 &lt;emphasis&gt; 和非 &lt;emphasis&gt; 版本之间没有区别:

var msg = new SpeechSynthesisUtterance();
msg.text = '<?xml version="1.0"?>\r\n<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US"><emphasis>Welcome</emphasis> to the Bird Seed Emporium.  Welcome to the Bird Seed Emporium.</speak>';
msg.lang = 'en';
speechSynthesis.speak(msg);

&lt;phoneme&gt; 标签也被完全忽略,这让我尝试说国际音标失败。

var msg = new SpeechSynthesisUtterance();
msg.text='<?xml version="1.0" encoding="ISO-8859-1"?> <speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/10/synthesis http://www.w3.org/TR/speech-synthesis/synthesis.xsd" xml:lang="en-US"> Pavlova is a meringue-based dessert named after the Russian ballerina Anna Pavlova. It is a meringue cake with a crisp crust and soft, light inside, usually topped with fruit and, optionally, whipped cream.  The name is pronounced <phoneme alphabet="ipa" ph="p&aelig;v&#712;lo&#650;v&#601;">...</phoneme> or <phoneme alphabet="ipa" ph="p&#593;&#720;v&#712;lo&#650;v&#601;">...</phoneme>, unlike the name of the dancer, which was <phoneme alphabet="ipa" ph="&#712;p&#593;&#720;vl&#601;v&#601;">...</phoneme> </speak>';
msg.lang = 'en';
speechSynthesis.speak(msg);

尽管 Microsoft 语音 API确实正确处理了 SSML,但还是会发生这种情况。这里是一个C# sn-p,适合在LinqPad中使用:

var str = "Pavlova is a meringue-based dessert named after the Russian ballerina Anna Pavlova. It is a meringue cake with a crisp crust and soft, light inside, usually topped with fruit and, optionally, whipped cream.  The name is pronounced /pævˈloʊvə/ or /pɑːvˈloʊvə/, unlike the name of the dancer, which was /ˈpɑːvləvə/.";
var regex = new Regex("/([^/]+)/");
if (regex.IsMatch(str))
{
    str = regex.Replace(str, "<phoneme alphabet=\"ipa\" ph=\"$1\">word</phoneme>");
    str.Dump();
}   
SpeechSynthesizer synth = new SpeechSynthesizer();
PromptBuilder pb = new PromptBuilder();
pb.AppendSsmlMarkup(str);
synth.Speak(pb);

【讨论】:

  • 同样的问题。
  • 使用当前的 Chrome 55.0,它甚至无法识别 XML。我的说话(msg)说的是“小于问号 ex em el 版本等于引用一点零引用......”
  • 我认为尚不支持 SSML :(
  • 截至 2020 年 5 月,它现在可以正常工作。版本 81.0.4044.138
  • 由于我的公司限制,我仍在构建 81.0.4044.129,它对我来说不能正常工作。 在我的系统上仍然被忽略。
猜你喜欢
  • 1970-01-01
  • 2019-04-12
  • 2021-05-21
  • 2020-06-30
  • 2013-04-09
  • 2014-08-30
  • 2011-10-05
  • 2015-03-18
相关资源
最近更新 更多