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

Remove previously recognized words from speech recognition api results

本文关键字:识别 单词 删除 语音识别 api 结果      更新时间:2023-09-26

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

这是我处理语音识别的基本方法。

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

通常我使用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/

我认为您正在附加结果。您不应该附加结果。你应该把结果重写一遍。比方说在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
    }

我希望这能让你知道你做错了什么。(假设您有结果的数组列表)