2012-03-21 19 views
1

我想通過說「你好,傑克」來喚醒Android APP中的某些功能。據我所知,有一種名爲「短語識別」的技術來識別特定的語音,例如, 「你好,傑克」。但我不知道要實施「詞組察覺」。如何在Android上獲得語音喚醒

任何人有更多的想法或建議嗎?

謝謝。

回答

-1

我首先提出這個簡單的方法。

開始使用簡單的設置來匹配你想要的,如下面的類的關鍵字:如果失敗介紹

@Override 
protected void 
     onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    WordMatcher matchHello = new WordMatcher("hello"); 
    WordMatcher matchJack = new WordMatcher("jack"); 

    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE) 
    { 
     if (resultCode == RESULT_OK) 
     { 
      List<String> heard = 
        data. 
        getStringArrayListExtra 
          (RecognizerIntent.EXTRA_RESULTS); 

      for (String oneResult : heard) 
      { 
       if (matchHello.isIn(oneResult.split(" ")) && matchJack.isIn(oneResult.split(" ")) 
       { 
        //SUCCESS!! do something here 
       } 


      } 
     } 
     else 
     { 
      Log.d(TAG, "error code: " + resultCode); 
     } 
    } 
    super.onActivityResult(requestCode, resultCode, data); 
} 

二:

public class WordMatcher 
{ 
    private Set<String> words; 
    public static final int NOT_IN = -1; 

    public WordMatcher(String... wordsIn) 
    { 
     this(Arrays.asList(wordsIn)); 
    } 

    public WordMatcher(List<String> wordsIn) 
    { 
     //care about order so we can execute isInAt 
     words = new LinkedHashSet<String>(wordsIn); 
    } 

    public Set<String> getWords() 
    { 
     return words; 
    } 

    public boolean isIn(String word) 
    { 
     return words.contains(word); 
    } 

    public boolean isIn(String [] wordsIn) 
    { 
     boolean wordIn = false; 
     for (String word : wordsIn) 
     { 
      if (isIn(word)) 
      { 
       wordIn = true; 
       break; 
      } 
     } 
     return wordIn; 
    } 

過程的識別結果是這樣「聽起來像」匹配算法,如Soundex

此外,您可能希望直接調查使用SpeechRecognizer類來在後臺運行語音識別,而不是使用生成對話框的RecognizerIntent。