0

感谢 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');
  }
4

2 回答 2

0

对于您的第一个问题,不要使用 onspeechend 使用 onend 继续收听

recognition.onend = function(event) {
  recognition.start();
  console.log('SpeechRecognition.onend');
}

这将使麦克风连续收听。

至于第二个问题,我不知道。希望这至少对第一个问题有所帮助!

于 2019-05-17T14:53:27.623 回答
0

在第一个代码示例中,您可能不想使用recognition.stop(). 并听result而不是speechend. 您可以将结果拼接在一起以获得整个结果。

于 2018-09-07T10:49:14.897 回答