Search code examples
androidspeech-to-textvibration

Vibration when SpeechToText function completes


I have implemented the SpeechToText function in a project of mine.I was wondering if it's possible to detect when the SpeechToText function has completed, so that I can implement a vibration right after. Can anyone tell me if this is possible? If so, please give me some details.Thanks! Here is the code I've implemented:

   @Override
public void onUtteranceCompleted(String utteranceId) {
    // TODO Auto-generated method stub
    // Get instance of Vibrator from current Context
            Vibrator mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

            // Vibrate for 300 milliseconds
            mVibrator.vibrate(300);

            Intent intent = new Intent(
                    RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

            try {
                startActivityForResult(intent, RESULT_SPEECH);
                feedbackTextView.setText("");
            } catch (ActivityNotFoundException a) {
                Toast t = Toast.makeText(getApplicationContext(),
                        "Opps! Your device doesn't support Speech to Text",
                        Toast.LENGTH_SHORT);
                t.show();

        }

}

Solution

  • in onActivityForResult

    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) 
     {
        Log.d(TAG, "onActivityResult"); //$NON-NLS-1$ 
    
        if (requestCode == RESULT_SPEECH) 
         {
           if (resultCode == RESULT_OK)
           {
             // User say something vibrate here
           }
           else
           {
              // User cancel
           }
        }
    
         super.onActivityResult(requestCode, resultCode, data);
     }