2014-07-06 49 views
2

我試圖使用Google Wear網站的自由格式語音輸入。模擬器中Google Wear上的語音識別器無語音輸入

從hello世界的例子中,我只是在textView上添加了一個點擊。它確實會從演講意圖中調出Speak Now活動,但模擬器無法檢測到我的麥克風發出的任何聲音。

我使用的是Mac OS 10.9.3,我已經嘗試了佩戴手錶的arm和intel版本,並檢查了AVD創建時的硬件鍵盤。該文檔說有一個系統內置的語音識別器,所以安裝谷歌語音應用程序就像你可能在移動模擬器中做的似乎是錯誤的答案?

public class MainActivity extends Activity { 

private TextView mTextView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub); 
    stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { 
     @Override 
     public void onLayoutInflated(WatchViewStub stub) { 
      mTextView = (TextView) stub.findViewById(R.id.text); 
      mTextView.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        displaySpeechRecognizer(); 
       } 
      }); 
     } 
    }); 
} 


private static final int SPEECH_REQUEST_CODE = 0; 

// Create an intent that can start the Speech Recognizer activity 
private void displaySpeechRecognizer() { 
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 

    // Start the activity, the intent will be populated with the speech text 
    startActivityForResult(intent, SPEECH_REQUEST_CODE); 
} 

// This callback is invoked when the Speech Recognizer returns. 
// This is where you process the intent and extract the speech text from the intent. 
@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) { 
     List<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); 
     String spokenText = results.get(0); 
     // Do something with spokenText 
    } 
    super.onActivityResult(requestCode, resultCode, data); 
} 

}

回答