使用Web Speech API使用SSML的正确方法

时间:2014-02-22 10:05:01

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

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

3 个答案:

答案 0 :(得分:4)

目前有关Chromium的问题存在漏洞。

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

答案 1 :(得分:4)

在Chrome 46中,当语言设置为en时,XML正在Windows上正确解释为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>标签也被完全忽略,这使我尝试说IPA失败。

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#代码段,适用于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);

答案 2 :(得分:0)

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