I've tried to get my code to work with the responsiveVoice API, but for some reason, it work work. It works with an "onclick" but not in an if statement. What am I doing wrong? Everything seems right to me, but it won't work. The code is shown below.
function record() {
var recognition = new webkitSpeechRecognition();
recognition.lang = "en-GB";
recognition.start();
recognition.onresult = function(event) {
let transcript = event.results[0][0].transcript;
var str = transcript;
if (str.includes('test')) {
responsiveVoice.speak('This works!');
}
document.getElementById('speechToText').value = event.results[0][0].transcript;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<label for="Speech Recognition">Speech Recognition</label>
<input type="text" name="" id="speechToText" placeholder="Speak Something" disabled="disabled">
<button onclick="record()">Record</button>
<p id="output"></p>
<script src='https://code.responsivevoice.org/responsivevoice.js'></script>
<script src="script.js"></script>
</body>
</html>Thanks for any help. I really appreciate it.
Aucun commentaire:
Enregistrer un commentaire