2

I am trying to make a sample app to demonstrate word by word recognition. So far i am able to achieve the speech recognition which recognise what already being said but i want my app to start recognising and typing words on go instead of waiting for user to finish the phrase or line. I know its possible in Android as i use it all the time in my sms app. The tutorial i found so far displaying Google Dialog which i dont want in my app.

Any help would be really appreciated.

This is my code so far which is displaying what has been just said by user without any issues : -

public class SpeechActivity extends Activity implements RecognitionListener, View.OnClickListener {

    private EditText editText;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        editText = (EditText)findViewById(R.id.abc);
        findViewById(R.id.bca).setOnClickListener(this);
    }

    @Override
    public void onReadyForSpeech(Bundle params) {
        Log.e("Speech", "Ready");
    }

    @Override
    public void onBeginningOfSpeech() {
        Log.e("Speech", "Begin");
    }

    @Override
    public void onRmsChanged(float rmsdB) {
        Log.e("Speech", "Rms");
    }

    @Override
    public void onBufferReceived(byte[] buffer) {
        Log.e("Speech", "Buffer Received");
    }

    @Override
    public void onEndOfSpeech() {
        Log.e("Speech", "End");
    }

    @Override
    public void onError(int error) {
        Log.e("Speech", "Error");
    }

    @Override
    public void onResults(Bundle results) {
        Log.e("Speech", "Result");
        if(results != null) {
            Log.e("Speech", results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION).toString());
            ArrayList<String> result = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            editText.setText(result.get(0));
        }
    }

    @Override
    public void onPartialResults(Bundle partialResults) {
        Log.e("Speech", "Partial Result");
        if(partialResults != null) {
            Log.e("Speech", partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION).toString());
            ArrayList<String> result = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            editText.setText(result.get(0));
        }
    }

    @Override
    public void onEvent(int eventType, Bundle params) {
        Log.e("Speech", "OnEvent");
    }

    @Override
    public void onClick(View v) {
        SpeechRecognizer speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "AndroidBite Voice Recognition...");
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                this.getPackageName());
        speechRecognizer.setRecognitionListener(this);
        speechRecognizer.startListening(intent);
    }
}

But as i said i want my app to recognise word by word speech and i don't want it to wait till the time user finish speaking.

Please help!!

Varundroid
  • 9,135
  • 14
  • 63
  • 93

0 Answers0