Google Wear在模拟器中的语音识别器无语音输入

时间:2014-07-06 15:00:54

标签: android wear-os android-speech-api

我试图使用Google Wear网站的自由格式语音输入。

从hello world示例中,我只是在textView上添加了一个单击。它确实从语音意图中调出了Speak Now活动,但模拟器无法从我的麦克风中检测到任何声音。

我正在使用Mac OS 10.9.3,我已经尝试了佩戴手表和英特尔版本的佩戴手表,并检查了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);
}

}

1 个答案:

答案 0 :(得分:2)

我通过这篇文章Receiving voice input from an Android wearable emulator想出你可以用键盘输入,我想现在可以了