2015-03-18 112 views
0

在使用Javascript語音識別API時,我發現我所有先前的語句都與最新的語句一起顯示,是否有一種方法可以在之後清除所有之前的語句一個新的短語已被認可?從語音識別api結果中刪除以前識別的單詞

這是我使用語音識別的基本方式。

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

回答

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 

    } 

我希望這可以讓你知道你在做什麼錯。 (假設你有結果列表)

+0

我使用的是javascript而不是java – Jordan 2015-03-19 11:37:35

+0

我提供了一個樣例@jordan。我認爲你可以將它轉換成你的語言並根據你的需要 – 2015-03-19 11:41:44

+0

我建議你在這個函數中保存結果字符串變量 recognition.onresult = function(event){ console.log(event); //像這裏一樣,然後嘗試註銷變量 } – 2015-03-19 11:43:04