从语音识别api结果中删除以前识别的单词

时间:2015-03-18 22:00:18

标签: javascript speech-recognition

在使用Javascript语音识别API时,我发现我之前的所有语句都与最新的语句一起显示,有没有一种方法可以在识别出新短语后清除所有以前的语句?

这是我使用语音识别的基本方法。

var recognition = new webkitSpeechRecognition();
recognition.continuous = true; 
recognition.interimResults = true;
recognition.start();
recognition.onresult = function(event){ 
    console.log(event);
}

2 个答案:

答案 0 :(得分:0)

我认为您正在追加结果。你不应该追加结果。你应该重写结果。让我们说在java

 @Override
public void onResults(Bundle results) {
    Log.i(LOG_TAG+">"+ "onResults");
    ArrayList<String> matches = results
            .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    String text = "";
    for (String result : matches)
        text += result + "\n";
    if(text.contains(my key word list here)){
       //you can skip this if part

    }

我希望这可以让你知道你做错了什么。 (假设你有结果的arraylist)

答案 1 :(得分:0)

通常我使用https://github.com/Manohar-Gunturu/rs.speech.js库。

speechRs.rec_start('en-IN',function(final_transcript,interim_transcript){
      console.log(final_transcript,interim_transcript);
      // final_transcript gives complete transcript from the beginning 
      // interim_transcript return the transcript the user has spoken 
      // from last break he took
}); 

https://jsfiddle.net/r6ftm7oq/此处查看演示