感谢 Matthew Terentjev 的出色工作在这里,我们可以在 Articulate Storyline 中使用 javascript 进行在线语音识别。下面的代码是通过一个按钮触发的。它简单干净,这让我更困惑,我尝试进行一些修改,其中两个让我觉得我是生活中的一个大失败:(
1)第一个是即使您添加此代码:
识别。连续=真;
...当用户在说话时暂停时,识别不会继续。即使我将这部分更改为:
recognition.onspeechend = function() {
recognition.start(); // I changed this line from recognition.stop();
console.log('Speech ended!');
}
2)我尝试失败的下一件事是:每次用户点击开始新的识别时,最后识别的文本应该消失,(不是当用户开始说话时,而是当他/她点击按钮时)。在过去的 24 小时内,我试图为此找到解决方案,但没有成功。
Storyline 项目中有一个按钮可以触发代码。以及一个附加到文本框的变量,该文本框负责为名为 SpeechReceived 的用户显示结果。
这是代码:
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList;
var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent;
var recognition = new SpeechRecognition();
var speechRecognitionList = new SpeechGrammarList();
recognition.grammars = speechRecognitionList;
recognition.lang = 'en-GB';
recognition.interimResults = false;
recognition.maxAlternatives = 1;
recognition.start();
recognition.onresult = function(event) {
var speechResult = event.results[0][0].transcript;
//return speech and change storyline variable with a result
var player = GetPlayer();
player.SetVar("SpeechReceived",speechResult);
console.log('Confidence: ' + event.results[0][0].confidence);
}
recognition.onspeechend = function() {
recognition.stop();
console.log('Speech ended!');
}
recognition.onerror = function(event) {
console.log('Error occurred in recognition: ' + event.error);
}
recognition.onaudiostart = function(event) {
//Fired when the user agent has started to capture audio.
console.log('SpeechRecognition.onaudiostart');
}
recognition.onaudioend = function(event) {
//Fired when the user agent has finished capturing audio.
console.log('SpeechRecognition.onaudioend');
}
recognition.onend = function(event) {
//Fired when the speech recognition service has disconnected.
console.log('SpeechRecognition.onend');
}
recognition.onnomatch = function(event) {
//Fired when the speech recognition can't recognise speech
console.log('SpeechRecognition.onnomatch');
}
recognition.onsoundstart = function(event) {
//Fired when any sound — recognisable speech or not — has been detected.
console.log('SpeechRecognition.onsoundstart');
}
recognition.onsoundend = function(event) {
//Fired when no sound present
console.log('SpeechRecognition.onsoundend');
}
recognition.onspeechstart = function (event) {
//Fired when speech starts
console.log('SpeechRecognition.onspeechstart');
}
recognition.onstart = function(event) {
//Fired when the speech recognition service has begun listening
console.log('SpeechRecognition.onstart');
}