How to activate speech to text using a button?

I would like to create a button that, when pressed, will activate speech in Android broadcast, like the one provided by the Android keyboard. In particular, I would like the button in which the application transcribes what the user is saying in real time and writes his word by word (in real time) in the editText field. What would be the best way to do this?

thanks

+6
source share
3 answers

If you have not tested the Voice Recognition sample in your Api demos yet, you should go and check it. This should give you a start. Demos are available in the /android-sdk/samples/... folder. If you have not installed them, here is how you can install the Android demo application on my phone .

Below are the following (any many others) tutorials to help you get started:

1) Android voice recognition tutorial

2) Android: speech in text using API

The following can be well read:

Add text and speech recognition to your Android applications and Use the Android speech recognition API .

Hope this helps.

+2
source

In your application, you call startActivityForResult() with the ACTION_RECOGNIZE_SPEECH action. This will start the speech recognition activity, and you will be able to process the result in onActivityResult() .

 private static final int SPEECH_REQUEST_CODE = 0; // Create an intent that can start the Speech Recognizer activity private void displaySpeechRecognizer() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); // Start the activity, the intent will be populated with the speech text startActivityForResult(intent, SPEECH_REQUEST_CODE); } // This callback is invoked when the Speech Recognizer returns. // This is where you process the intent and extract the speech text from the intent. @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) { List<String> results = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS); String spokenText = results.get(0); // Do something with spokenText } super.onActivityResult(requestCode, resultCode, data); } 

Further information can be found in the link.

0
source
 private void startVoiceRecognitionActivity() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo..."); startActivityForResult(intent, REQUEST_CODE); } /** * Handle the results from the voice recognition activity. */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { // Populate the wordsList with the String values the recognition engine thought it heard ArrayList<String> matches = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS); myEditText.setText(matches.get(0)); } super.onActivityResult(requestCode, resultCode, data); } 
0
source

Source: https://habr.com/ru/post/947965/


All Articles