3

The idea is to take a user voice input on the press of a button and pass it to the search inside the app. Because of device limitations we are using the SearchViewCompat instead of the useful SearchView. I have been able to grab the voice output using this link, but there is not a simple way to pass the text to the search bar this way.
The search view itself shows as a view (so no setText()), but if I can just say "use mic key on keyboard" or something as soon as the searchbar comes up, I think it might work. Any help would be greatly appreciated.
Thanks, SGB.

Silas Greenback
  • 1,200
  • 8
  • 15

2 Answers2

3

No, it's not possible. At least, there is no simple way to launch voice input without using RecognitionListener or manually clicking the voice input button on soft keyboard.

As far as I know, this post explains how to integrate voice into an IME which actually uses this library: google-voice-typing-integration. It might inspire you a bit.

Aaron He
  • 5,509
  • 3
  • 34
  • 44
  • Well, this is not really what I was looking for, but this is some great information here. I may use the RecognitionListener for a second or third option. – Silas Greenback Feb 14 '13 at 15:22
  • You can create a view contains a button to trigger voice input. Then call it when appropriate, like `EditText.OnClickListener`. Take a look at this question: http://stackoverflow.com/questions/1896939/android-app-specific-soft-keyboard – Aaron He Feb 14 '13 at 18:55
1

Sorry to have answered my own question but here it was: I took the whole "grab a string array from voice input" off of the link in the question, then, instead of just starting a search with onSearchRequested(), I did this:

startSearch(grabString, false, null, false);


public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(aViaBuildConfig.MIC_KEY) {
        DebugLog.e(TAG , "onDown event : " + event);
        DebugLog.e(TAG , "onDown keyCode: " + keyCode);
        if(keyCode == Constants.MIC_KEY) {
            onSearchRequested();
            Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
            try {
                startActivityForResult(voiceIntent, Constants.RESULT_SPEECH);
            } catch (ActivityNotFoundException ex) {
                DebugLog.e(TAG, "Not found excpetion onKeyDown: " + ex);
            }
        }
        return super.onKeyDown(keyCode, event);
    }
    return false; 
}


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case Constants.RESULT_SPEECH:
            super.onActivityResult(requestCode, resultCode, data);
            if (resultCode == RESULT_OK && null != data) {
                 ArrayList<String> spokenSearch = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                 DebugLog.e("Glenn: " , "Speech = " + spokenSearch);
                 String grabString = spokenSearch.get(0);
                 startSearch(grabString, false, null, false);
            }
            break;
    }
}
Karu
  • 4,512
  • 4
  • 30
  • 31
Silas Greenback
  • 1,200
  • 8
  • 15
  • Sorry for the lack of comments: Part 1 is just grabbing the keyDown and launching the "get coive stuff" activity in the android way, and the second is grabbing the answer and passing it to the search. The key bit is the startSearch(grabString, false, null, false); – Silas Greenback Feb 15 '13 at 21:19