I accidentally saw it online. So I wrote an example based on the online example. It is easy to implement speech recognition. Later TTS was not done.
Directly paste code
View Code
/*** Speech Recognition *** @ author sy **/public class SpeakToActivity extends Activity {/** Called when the activity is first created. */private Button mSpeakButton; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); mSpeakButton = (Button) findViewById (R. id. openSpeak); mSpeakButton. setOnClickListener (new ButtonOnClick ();}/*** button click event ** @ author sy **/class ButtonOnClick implements OnClickListener {@ Override public void onClick (View v) {try {// TODO Auto-generated method stub Intent intent = new Intent (RecognizerIntent. ACTION_RECOGNIZE_SPEECH); // use Intent to start Speech Recognition /// Speech Recognition intent in both language and free modes. putExtra (RecognizerIntent. EXTRA_LANGUAGE_MODEL, RecognizerIntent. LANGUAGE_MODEL_WEB_SEARCH); intent. putExtra (RecognizerIntent. EXTRA_PROMPT, "Start voice"); // only prompts the voice to start startActivityForResult (intent, 10); // The requestCode} catch (Exception e) {e in the onActivityResult method. printStackTrace (); // If the Voice device cannot be found, the Toast message is displayed. makeText (SpeakToActivity. this, "cannot find the Voice device", Toast. LENGTH_LONG ). show () ;}}/*** activity callback function, corresponding to startActivityForResult ** @ author sy */@ Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {// TODO Auto-generated method stub super. onActivityResult (requestCode, resultCode, data); if (requestCode = 10 & resultCode = RESULT_ OK) {ArrayList <String> results = data. getStringArrayListExtra (RecognizerIntent. EXTRA_RESULTS); // obtain the result set String resultString = ""; // if you use this annotation code, google returns five words that are similar to your pronunciation // for (int I = 0; I <results. size (); I ++) // {// resultString + = results. get (I); //} resultString + = results. get (0); // I select the first Toast by default. makeText (SpeakToActivity. this, resultString, Toast. LENGTH_LONG ). show ();}}}