我正在使用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>