次のデモを使用して音声を認識しています。動作していますが、音声テキストの読み込みまたは認識に時間がかかることがあります。なぜだかわからない!しかし、デフォルトの最大タイムアウトを超えた場合に他のコールバック関数を呼び出すように、認識関数のデフォルトのタイムアウトを設定する方法はありますか?
<script>
// Test browser support
window.SpeechRecognition = window.SpeechRecognition ||
window.webkitSpeechRecognition ||
null;
if (window.SpeechRecognition === null) {
document.getElementById('ws-unsupported').classList.remove('hidden');
document.getElementById('button-play-ws').setAttribute('disabled', 'disabled');
document.getElementById('button-stop-ws').setAttribute('disabled', 'disabled');
} else {
var recognizer = new window.SpeechRecognition();
var transcription = document.getElementById('transcription');
var log = document.getElementById('log');
// Recogniser doesn't stop listening even if the user pauses
recognizer.continuous = true;
// Start recognising
recognizer.onresult = function(event) {
transcription.textContent = '';
for (var i = event.resultIndex; i < event.results.length; i++) {
if (event.results[i].isFinal) {
transcription.textContent = event.results[i][0].transcript + ' (Confidence: ' + event.results[i][0].confidence + ')';
} else {
transcription.textContent += event.results[i][0].transcript;
}
}
};
// Listen for errors
recognizer.onerror = function(event) {
log.innerHTML = 'Recognition error: ' + event.message + '<br />' + log.innerHTML;
};
document.getElementById('button-play-ws').addEventListener('click', function() {
// Set if we need interim results
recognizer.interimResults = document.querySelector('input[name="recognition-type"][value="interim"]').checked;
try {
recognizer.start();
log.innerHTML = 'Recognition started' + '<br />' + log.innerHTML;
} catch(ex) {
log.innerHTML = 'Recognition error: ' + ex.message + '<br />' + log.innerHTML;
}
});
document.getElementById('button-stop-ws').addEventListener('click', function() {
recognizer.stop();
log.innerHTML = 'Recognition stopped' + '<br />' + log.innerHTML;
});
document.getElementById('clear-all').addEventListener('click', function() {
transcription.textContent = '';
log.textContent = '';
});
}
</script>
前もって感謝します!