2017-01-09 10 views
7

używam Chrome w wersji 55.0.2883.87 m (64-bitowy) Windows 10.speechSynthesis.speak nie działa w Chrome

Poniższy prosty plik html reprodukuje problem i jest pobierany z moim bardziej złożonych aplikacji. Powinien mówić 3 słowa przy ładowaniu strony. Działa na MS Edge i Firefox, ale nie działa na chrome. Ten kod działa dla mnie w Chrome bez problemu kilka tygodni temu.

<html> 
<head> 
    <script lang="javascript"> 
     window.speechSynthesis.speak(new SpeechSynthesisUtterance("cat")); 
     window.speechSynthesis.speak(new SpeechSynthesisUtterance("dog")); 
     window.speechSynthesis.speak(new SpeechSynthesisUtterance("bark")); 
    </script> 
</head> 
<body></body> 
</html> 

Odpowiedz

0

resultsDisplay = document.getElementById("rd"); 
 
startButton = document.getElementById("startbtn"); 
 
stopButton = document.getElementById("stopbtn"); 
 

 
recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition || window.mozSpeechRecognition || window.msSpeechRecognition)(); 
 
recognition.lang = "en-US"; 
 
recognition.interimResults = false; 
 
recognition.maxAlternatives = 5; 
 

 
recognition.onresult = function(event) { 
 
    resultsDisplay.innerHTML = "You Said:" + event.results[0][0].transcript; 
 
}; 
 

 
function start() { 
 
    recognition.start(); 
 
    startButton.style.display = "none"; 
 
    stopButton.style.display = "block"; 
 
} 
 

 
function stop() { 
 
    recognition.stop(); 
 
    startButton.style.display = "block"; 
 
    stopButton.style.display = "none"; 
 
}
.resultsDisplay {width: 100%; height: 90%;} 
 
#stopbtn {display: none;}
<div class="resultsDisplay" id="rd"></div> 
 
<br/> 
 

 
<center> 
 
    <button onclick="start()" id="startbtn">Start</button> 
 
    <button onclick="stop()" id="stopbtn">Stop</button> 
 
</center>

Spróbuj

utterance = new SpeechSynthesisUtterance("cat, dog, bark"); 
speechSynthesis.speak(utterance); 

Zrobiłem Weave na LiveWeave.

Powiązane problemy