这是我在stackoverflow上的第一个问题,很抱歉,如果我做错了什么。 我在android服装上有一个应用程序,用户应从列表中选择一个项目。
我想让用户通过语音命令选择项目。我设法按照google documentation中的建议进行操作,但我必须实现一个按钮来启动语音识别,它将显示为全屏活动。
我希望用户能够在语音识别处于活动状态时查看列表。对此有什么解决方案吗?
编辑:我可能找到了我想要的解决方案。它是语音识别器,似乎能够做到我想要的。如果是解决方案的话,我将不得不深入研究并发布这篇文章。答案 0 :(得分:0)
您找到了解决方案吗?我使用了SpeechRecognizer类,它必须在主线程中实现Recognition侦听器,或者你可以有一个实现相同的内部类。
SpeechListenerClass speechListenerObj;
SpeechRecognizer speechRecognizerObj;
Intent speechRecognizerIntentObj;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
speechListenerObj = new SpeechListenerClass(getApplicationContext(),this);
speechRecognizerObj = SpeechRecognizer.createSpeechRecognizer(this);
speechRecognizerIntentObj = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
speechRecognizerIntentObj.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,"en");
` ``````````` speechRecognizerIntentObj.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent. LANGUAGE_MO DEL_WEB_SEARCH);
speechRecognizerIntentObj.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
speechRecognizerIntentObj.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,this.getPackageName());
speechRecognizerObj.startListening(speechRecognizerIntentObj);
speechRecognizerObj.setRecognitionListener(new Listener());
}
class Listener implements RecognitionListener
{
@Override
public void onReadyForSpeech(Bundle params) {
}
@Override
public void onBeginningOfSpeech() {
}
@Override
public void onRmsChanged(float rmsdB) {
}
@Override
public void onBufferReceived(byte[] buffer) {
}
@Override
public void onEndOfSpeech() {
}
@Override
public void onError(int error) {
}
@Override
public void onResults(Bundle results) {
}
@Override
public void onPartialResults(Bundle partialResults) {
}
@Override
public void onEvent(int eventType, Bundle params) {
}
}
这适用于我,但问题是它会在Android Wear设备(Moto 360)中显示Google搜索对话框。在手机上运行时相同的代码充当后台任务。如果要做任何改动,请告诉我。