0

To be brief, I want to create an android widget that reads out an address that is stored within the widget upon clicking it.

After looking at the answer from this link that does speech to text, which I've posted below, I want to know whether its possible to do text to speech in a similar way.

// this intent points to activity that should handle results
Intent activityIntent = new Intent(context, ResultsActivity.class);
// this intent wraps results activity intent
PendingIntent resultsPendingIntent = PendingIntent.getActivity(context, 0, activityIntent, 0);

// this intent calls the speech recognition
Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
voiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, resultsPendingIntent);

// this intent wraps voice recognition intent
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, voiceIntent, 0);
rv.setOnClickPendingIntent(R.id.btn, pendingIntent);
Community
  • 1
  • 1
consprice
  • 722
  • 3
  • 11
  • 21

1 Answers1

0

Text-to-speech and speech recognition work in different ways. Speech recognition is a separate Activity (so has to be used via an Intent) but text to speech can be done without leaving your Activity.

So you could do text to speech the same way, by creating an activity of your own that is solely for speaking text, then using a modified version of the code you've posted to go to it, but I'm not sure you'd want to. Is there a reason you want to go to another Activity to do the TTS? It's simpler to stay within the same Activity for it.

hcarver
  • 7,126
  • 4
  • 41
  • 67
  • I wanted to create a text to speech function in the AppWidgetProvider class, but only saw examples of text to speech in Actvity classes, and wondered if it was possible to do it in AppWidgetProvider class. It seems that I will have to create a service for the widget to do TTS. Thanks for the answer though:) – consprice Aug 04 '12 at 01:23