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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:37:13+00:00 2026-05-20T01:37:13+00:00

I have been able to run TTS from an activity but when I try

  • 0

I have been able to run TTS from an activity but when I try to execute the same code from a service, it’s giving me message that TTS engine is initialised but not speaking anything.

Has anybody encountered the same issue anytime?

 public void onCreate() {

    super.onCreate();
    tts = new TextToSpeech(this, this //TextToSpeech.OnInitListener);

    timer.scheduleAtFixedRate( new TimerTask()                       
    {                                   // In timer

          public void run() {
          //On some condition
          tts.speak("thank you", TextToSpeech.QUEUE_ADD, null);
     }, 0, 60000);
    }

  @Override
  public void onInit(int status) {  
  if (status == TextToSpeech.SUCCESS) {
  Toast.makeText(BackgroundProcessforTimecheck.this, 
  "Text-To-Speech engine is initialized", Toast.LENGTH_LONG).show();
 }
 else if (status == TextToSpeech.ERROR) {
  Toast.makeText(BackgroundProcessforTimecheck.this, 
  "Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();
}
}
  • 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-05-20T01:37:14+00:00Added an answer on May 20, 2026 at 1:37 am

    I had the same problem and solved it this way:
    Instantiate TextToSpeech Object in a separate Class (in my case I furthermore use a Factory to check if the Android Version is at least Donut) and reuse it (see method init(Context context)). Please notice that the onInit(int status) is far from being ready to release.

    Service:

    @Override
    public void onStart(Intent intent, int startId) {
    Context context = getApplicationContext();
    TtsProviderFactory ttsProviderImpl = TtsProviderFactory.getInstance();
    if (ttsProviderImpl != null) {
        ttsProviderImpl.init(context);
        ttsProviderImpl.say("hope that helps);
    }}
    

    Factory:

    public abstract class TtsProviderFactory {
    
    public abstract void say(String sayThis);
    
    public abstract void init(Context context);
    
    public abstract void shutdown();
    
    
    private static TtsProviderFactory sInstance;
    
    public static TtsProviderFactory getInstance() {
        if (sInstance == null) {
            int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
            if (sdkVersion < Build.VERSION_CODES.DONUT) {
                return null;
            }
    
            try {
                String className = "TtsProviderImpl";
                Class<? extends TtsProviderFactory> clazz =
                        Class.forName(TtsProviderFactory.class.getPackage().getName() + "." + className)
                                .asSubclass(TtsProviderFactory.class);
                sInstance = clazz.newInstance();
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        }
        return sInstance;
    }}
    

    Implementation:

    public class TtsProviderImpl extends TtsProviderFactory implements TextToSpeech.OnInitListener {
    
    private TextToSpeech tts;
    
    public void init(Context context) {
        if (tts == null) {
            tts = new TextToSpeech(context, this);
        }
    }
    
    @Override
    public void say(String sayThis) {
        tts.speak(sayThis, TextToSpeech.QUEUE_FLUSH, null);
    }
    
    @Override
    public void onInit(int status) {
        Locale loc = new Locale("de", "", "");
        if (tts.isLanguageAvailable(loc) >= TextToSpeech.LANG_AVAILABLE) {
            tts.setLanguage(loc);
        }
    }
    
    public void shutdown() {
        tts.shutdown();
    }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on information extraction and was able to run standAloneAnnie.java http://gate.ac.uk/wiki/code-repository/src/sheffield/examples/StandAloneAnnie.java
I have been able to run the Static Analyzer on my code fine for
I have been able to run my C# .net 3.5 app just fine on
What I have been able to grasp from reading the source and documentation from
There have been a few threads on this topic but none have been able
I have been able to run some web services locally through Maven's jetty plugin
I've run into this issue in the past, and have been able to work
I have an asterisk-based PBX, and I have been able to successfully run an
I have been able to use gnuplot to plot graphs as I run my
I have been able to make my photos large for single photo posts on

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.