Web Speech API - SpeechSynthesisUtterance onmark 事件不会触发

Web Speech API - SpeechSynthesisUtterance onmark event wont fire

使用 SSML 时,我无法在 Chrome 或 Edge 中触发“onmark”事件。 我已经在 Chrome 和 Edge 中尝试过,并根据 https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API

中的标准编写了代码

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/TTS/DMAC.TTS.SSML.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input id="btnSpeak" type="button" onclick="Speak(); return false;" value="Speak" />
        </div>
        <div id="output"></div>
    </form>
</body>

<script>
    var synth = window.speechSynthesis;
    var voices = null;
    function Speak() {
        var utterance = new SpeechSynthesisUtterance();
        utterance.onboundary = function (event) {
            document.getElementById('output').innerHTML += 'onboundary Event: ' + event.toString() + "<br/>";
        };
        utterance.onmark = function (event) {
        document.getElementById('output').innerHTML += 'onmark Event: ' + event.toString() + "<br/>";
        }
        utterance.text = '<mark name="w1"/>Hello <mark name="w2"/>my <mark name="w3"/>name <mark name="w4"/>is <mark name="w5"/>John.';
        utterance.lang = 'en-US';
        utterance.voice = voices[0];
        synth.speak(utterance);
    };
    window.speechSynthesis.onvoiceschanged = function () {
        voices = synth.getVoices();
    };
</script>
</html>

对于基于远程 tts 服务的语音,在 Chrome 上似乎没有正确触发 onboundary 事件。检查 localService 属性 是否有你打算使用的声音,select localService = true voices only.

在 Edge 上,所有声音的 onboundary 事件都正确触发。

奇怪的是,Chromium 团队将这个已知问题标记为“wontfix”, https://bugs.chromium.org/p/chromium/issues/detail?id=521666