This is my first question here on stackoverflow, so sorry if i am doing something wrong.
I have an app on android wear, where the user shall select an item from a list.
I want to enable the user to select the item via voice commands. I managed to do it as suggested in the google documentation, but i have to implement a button to start speech recognition, and it will show up as a fullscreen activity.
I want the user to be able to see the list while speech recognition is active. Is there any solution for this?
EDIT: I might have found the solution i was looking for. It is the speech recognizer, which seems to be able to do just what i want. I will have to dig into that and will update this post if it is the solution.
Did you find a solution yet ? I have used SpeechRecognizer class which has to be in main thread with implementing the Recognition listener or you can have an inner class which implements the same.
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) {
}
}
This works for me but the problem is it brings up the Google search dialogue in Android Wear device(Moto 360) . The same code when run on phone acts as a background task. Please let me know if any changes are to be done..