Speech Recognition: Speech to text in Sketchware





We can implement Speech recognition using codes in add source directly block in Sketchware. Follow the steps below to implement Speech recognition in Sketchware.

1. Create a new android project in Sketchware.

2. In VIEW area add a Button button1 and an EditText edittext1 (or a TextView).



3. Add a new FilePicker component fp.



4. Add a new More Block extra.



5. To define this block extra, use an add source directly block and put following code in it:
}
public static final int REQ_CODE_SPEECH_INPUT = 1;
{



6. In the event button1 onClick, use an add source directly block and put following code:
Intent intent = new Intent(android.speech.RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE_MODEL, android.speech.RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); intent.putExtra(android.speech.RecognizerIntent.EXTRA_PROMPT, "Speak Now");
try { startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); }
catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(), "There was an error", Toast.LENGTH_SHORT).show(); }

7. Add the event FilePicker onFilesPicked. Here use an add source directly block and put following code:
}
break;
case REQ_CODE_SPEECH_INPUT:
if (_resultCode == RESULT_OK && null != _data) {
ArrayList<String> result = _data.getStringArrayListExtra(android.speech.RecognizerIntent.EXTRA_RESULTS);
edittext1.setText(result.get(0));
8. Save and run the project. Now in the app, the Button can be pressed to speak things to be written in the EditText field.


http://www.sketchwarehelp.com/2018/08/speech-recognition-speech-to-text-in.html