16

Web Speech API 规范说:

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

它没有提供使用textSSML 文档的示例。

我在 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 是否违反规范(应报告为错误),或者我的代码是否无效。

4

3 回答 3

4

There are bugs for this issue currently open with Chromium.

  • 88072: Extension TTS API platform implementations need to support SSML
  • 428902: speechSynthesis.speak() doesn't strip unrecognized tags This bug has been fixed in Chrome as of Sept 2016.
于 2015-03-19T13:28:36.553 回答
4

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

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);

<phoneme>标签也被完全忽略,这使我尝试说国际音标失败。

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,但还是会这样做。这是一个适用于LinqPad的 C# 片段:

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);
于 2015-11-21T18:32:49.847 回答
0

我已经对此进行了测试,并且 XML 解析似乎在 Windows 中可以正常工作,但是在 MacOS 中不能正常工作。

于 2018-12-27T22:41:15.880 回答