我在 Mobile Safari 中使用语音合成,发现它非常不稳定,特别是在说话过程中操纵 DOM 时。我创建了一个简单的测试用例,它在 iPad 上的 iOS 7.1.1 上使 Safari(或 Webview)崩溃(但在 OS X Safari 上运行良好)。有谁知道为什么下面的 HTML 页面会杀死移动 Safari?
<!DOCTYPE html>
<html>
<head>
<title>Speech Bug</title>
<script>
function testFunc()
{
var elem = document.getElementById("textout");
var wordCount = 0, utterance = new SpeechSynthesisUtterance("You'll notice that Safari on iOS will crash after clicking this button several times.");
utterance.onstart = function(event) {
elem.innerHTML = "";
}
utterance.onboundary = function (event) {
elem.innerHTML += ++wordCount + "\n";
elem.scrollTop = wordCount * 22;
}
window.speechSynthesis.speak(utterance);
}
</script>
</head>
<body>
<div id="textout" style="white-space: pre; font-size: 14pt; height: 100px; width: 50px; overflow: auto"></div>
<button onclick="testFunc()">Click to Fail</button>
</body>
</html>