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 8213025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:58:27+00:00 2026-06-07T10:58:27+00:00

The TextToSpeech constructor looks like it’s designed to be ‘owned’ by an Activity. I’m

  • 0

The TextToSpeech constructor looks like it’s designed to be ‘owned’ by an Activity. I’m producing an app with multiple different Activities, and I don’t want to have to initialise a new TextToSpeech instance for each – I want the speech to carry on smoothly even if the Activity is changing.

My idea is to have a static TextToSpeech object accessed by all activities, initialised by the first one.

  1. Does anyone know if the TextToSpeech implementation is thread-safe? I’m guessing not, but someone out there might know.
  2. If I initialise it with the Context of my default Activity, will the TextToSpeech instance stop working when the Activity is destroyed?
  • 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-07T10:58:30+00:00Added an answer on June 7, 2026 at 10:58 am

    Thanks to those that told me to pass the ApplicationContext. Turned out that was the easy bit… The hard bit was whether the TextToSpeech object is guaranteed thread-safe.

    Thanks for answers telling me how to make something thread-safe / assuming that it is, but the question was about whether the object already is. I probably should have said, I’m fine with implementing thread-safety, but I wanted to know whether I need to bother. And I don’t want to assume thread-safety without being certain.

    I ran the following and it seemed to work. So I assume the Android SDK TTS is thread-safe, but can’t find any documentation saying that it’s safe to assume this across all devices, so I’ll be wrapping my TTS instance for the time being!

    package com.example.testproject;
    
    import java.util.Random;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.speech.tts.TextToSpeech;
    import android.speech.tts.TextToSpeech.OnInitListener;
    
    public class TestActivity extends Activity implements OnInitListener {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            tts = new TextToSpeech(getApplicationContext(), this);
        }
    
        TextToSpeech tts = null;
    
        @Override
        public void onInit(int arg0) {
            for (int i = 0; i < 100; ++i) {
                class Irritate implements Runnable {
                    Irritate(int iIn) {
                        i = iIn;
                    }
    
                    @Override
                    public void run() {
                        Random r = new Random();
                        try {
                            Thread.sleep(r.nextInt(2000));
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
    
                        tts.speak(Integer.toString(i), TextToSpeech.QUEUE_ADD, null);
                    }
    
                    int i;
                }
    
                Thread t = new Thread(new Irritate(i));
    
                t.start();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I added TextToSpeech to my app, following the guidelines in the following post: http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html
So I've got an activity in my android app, that runs on start. This
I have an android app that uses TextToSpeech. I check to see if the
My activity's onInit() contains a call to TextToSpeech.setEngineByPackageName() : tts = new TextToSpeech(this, this);
I am developing Android TextToSpeech app. This application is not working in Android 1.5
I would like to do this: Sistema.Util.MP3Player(@sound1.mp3); Sistema.Util.MP3Player(@sound2.mp3); namespace Sistema.Util.TextToSpeech { public class Player
While developing TextToSpeech got a doubt that if we pause the activity how can
error message The constructor TextToSpeech(SQLiteExample, SQLiteExample) is undefined 04-16 04:06:19.860: E/AndroidRuntime(1728): Caused by: java.lang.ClassCastException:
package com.testotspeech; import java.util.ArrayList; import java.util.Arrays; import java.util.Locale; import android.app.Activity; import android.os.Bundle; import android.speech.tts.TextToSpeech;
result = tts.setLanguage(Locale.CHINA); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e(TTS, This

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.