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

  • Home
  • SEARCH
  • 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 recently learning some OOP PHP and seem to have run into
I have been trying to decide if my web project is a candidate for
I run Mac OS X 10.5.8. I would like to be able to run
I have been trying to teach myself MEF, starting with this tutorial: http://blogs.msdn.com/b/brada/archive/2008/09/29/simple-introduction-to-composite-applications-with-the-managed-extensions-framework.aspx There
I am trying to setup a maven project such that I will be able
In the web service I'm working on, I need to implement a URI with
Scenario: I have several services that I want to be discovered by different clients.
I have built an ASP.NET MVC 3 web application (with exlusively Razor/cshtml pages) that
hey guys so im building an application and one of teh features it will
Up until now I've only used DLL's as a source for plugins in my

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.