Chrome 将SSML与Web Speech API结合使用的正确方法

ryevplcw  于 2022-12-06  发布在  Go
关注(0)|答案(4)|浏览(189)

Web Speech API规范指出:

*文本 * 属性

此属性指定此话语要合成与朗读得文本.它可以是纯文本或完整得,格式正确得SSML文档.对于不支持SSML或只支持某些标记得语音合成引擎,用户代理或语音引擎必须去掉它们不支持得标记并朗读文本.
它没有提供在SSML文档中使用text的示例。
我在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是否违反了规范(应该作为bug报告),或者我的代码是否无效。

j8ag8udp

j8ag8udp1#

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

尽管微软语音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);
sbtkgmzw

sbtkgmzw2#

Chromium当前存在与此问题相关的漏洞。

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

slhcrj9b3#

我已经在Chrome 104.0.5112.101(Linux)上试过了。没有用。当我检查调试控制台时,我得到了这样的消息:

speechSynthesis.speak() without user activation is deprecated and will be removed

添加一个像The question of whether speechSynthesis is allowed to run without user interaction中提到的按钮确实对我有用。至少可以说出文本,而不是SSML格式的文本。

ix0qys7i

ix0qys7i4#

我已经测试过了,XML解析似乎在Windows中可以正常工作,但在MacOS中却不能正常工作。

相关问题