2017-01-09 9 views
7

Ich bin mit Chrom Version 55.0.2883.87 m (64-Bit) unter Windows 10.speechSynthesis.speak nicht in Chrom arbeiten

Die folgende einfache HTML-Datei von meiner komplexeren App extrahiert, um das Problem und wird wiedergibt. Es soll die 3 Wörter beim Laden der Seite sprechen. Es funktioniert auf MS Edge und Firefox, funktioniert aber nicht auf Chrome. Dieser Code funktionierte für mich auf Chrome kein Problem vor ein paar Wochen.

<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> 

Antwort

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>

Versuchen

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

ich Weave bei LiveWeave gemacht.

Verwandte Themen