Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:20:49+00:00 2026-06-09T21:20:49+00:00

I am trying to use TextToSpeech but i have some strange problems. Let me

  • 0

I am trying to use TextToSpeech but i have some strange problems.

Let me explain my application’s architecture simply. This application will be used for bus hours. Users can add their buses to notification. Server will notify subscribers if anything changes. I want to use TTS with this application.

I implemented Android GCM and notification system, only problem is TTS.

GCMIntentService.onMessage method calls generateNotification method below:

public static void generateNotification(Context context, String message) {
        int icon = R.drawable.icon_small;
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);
        String title = context.getString(R.string.app_name);       

        Bundle b = new Bundle();
        b.putString(EXTRA_MESSAGE, message);
        b.putString(READABLE_MESSAGE, message);

        Intent notificationIntent = new Intent(context, BusAlerts.class);
        notificationIntent.putExtra("CallType", CallType.NOTIFICATION);
        notificationIntent.putExtra("MessageReceived", b);
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent intent =
                PendingIntent.getActivity(context, 0, notificationIntent,  Intent.FLAG_ACTIVITY_NEW_TASK);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;
        long[] vibrate = { 1000 };
        notification.vibrate = vibrate;          
        notificationManager.notify(0, notification);
    }

This code successfully generates notification. Here is BusAlerts.codes (some trimmed ;))

public class BusAlerts extends Activity implements OnInitListener {
private static TextToSpeech myTts;

@Override
    public void onCreate(Bundle savedInstanceState) {
        myTts = new TextToSpeech(this, null);
}

@Override
protected void onStart() {
        super.onStart();

//readableMessage extracts from bundles

speak(readableMessage);
}

public void speak(String text)
    {
         myTts.speak(text, TextToSpeech.QUEUE_FLUSH, null);     
    }
@Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
         if (myTts != null) {
             myTts.shutdown();
             myTts.stop();
             myTts = null;
            }
    }
public void onInit(int status) {
         if (status == TextToSpeech.SUCCESS) {

                int result = myTts.setLanguage(Locale.UK);

                if (result == TextToSpeech.LANG_MISSING_DATA
                        || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                    Log.e("TTS", "This Language is not supported");
                } 
                else{
                    if (myTts.isLanguageAvailable(Locale.UK) == TextToSpeech.LANG_AVAILABLE || myTts.isLanguageAvailable(Locale.UK) == TextToSpeech.LANG_COUNTRY_AVAILABLE)
                        myTts.setLanguage(Locale.UK);
                }

            } else {
                Log.e("TTS", "Initilization Failed!");
            }

    }

If users open this class from notification, everything works perfect but no sound coming out. When i debug it i see a situation as below.
enter image description here

But if user presses Home button and reopens application (same activity resumes) user can hear sound.
Its situation is like this.
enter image description here

As i noticed mCachedParamters and mITts differs; but i don’t know why.
I have been stucked it for a week and couldn’t find solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:20:50+00:00Added an answer on June 9, 2026 at 9:20 pm

    You should call

    speak(readableMessage);
    

    only after OnInit has been called.
    By calling this in Onstart you are not guaranteed of this. That is the reason when you come back to application it is initialized and you are able to hear

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying use Thread but i have some problem (I am beginner at
I am trying use gem tire to search in my application. I have tables
Im trying use a Java annotation in a Groovy class but have trouble to
Hi I'm trying use a datepicker on a field I have. I'm trying to
I am need paint my image. I'm trying use JQuery in here this link:
I am trying use javascript regular expressions to do some matching and I found
I have been trying use the edit_post_link() function to contain an image. All of
Trying to use this sql statement. The first 2 parts work fine, I am
trying to use the preferred on method call but the code is not working
I am trying use filehelpers class builder but I am kinda confused on what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.