我试图使用 Google Wear 网站上的自由形式语音输入。
在 hello world 示例中,我刚刚添加了对 textView 的单击。它确实从语音意图中调出“立即发言”活动,但模拟器无法检测到我的麦克风发出的任何声音。
我使用的是 Mac OS 10.9.3,我尝试了 ARM 和 Intel 版本的佩戴手表,并检查了 AVD 创建中存在的硬件键盘。文档说有一个系统内置语音识别器,因此像在移动模拟器中那样安装 Google Voice 应用程序似乎是一个错误的答案?
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);
}
}
我通过这篇文章弄清楚了从 Android 可穿戴模拟器接收语音输入 https://stackoverflow.com/questions/22513974/receiving-voice-input-from-an-android-wearable-emulator你可以使用键盘进行输入,我想现在还可以
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)