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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:07:31+00:00 2026-05-27T03:07:31+00:00

I’ve got a problem with TTS in a Service . It acts like it

  • 0

I’ve got a problem with TTS in a Service. It acts like it wants to talk but it never does. Watching the LogCat it prints “TTS received: the text it should speak” and I Log when it init’s and that’s showing success. I’ve tried creating a thread for it, that didnt help.
onUtteranceComplete never triggers either. I’ve even done a while loop like this (just for testing):

while(mTTS.isSpeaking()) {
      Log.d("", "speaking");
}

…and it’s never speaking

I know TTS is setup correctly because it works in a regular Activity

Here’s my code.

import java.util.HashMap;
import java.util.Locale;

import android.app.Service;
import android.content.Intent;
import android.media.AudioManager;
import android.os.IBinder;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
import android.util.Log;

public class TTSService extends Service implements OnInitListener, OnUtteranceCompletedListener {
TextToSpeech mTTS;

    @Override
    public void onCreate() {
        Log.d("", "TTSService Created!");
        mTTS = new TextToSpeech(getApplicationContext(), this);


        //I've tried it in a thread....
        /*new Thread(new Runnable() {
            @Override
            public void run() {
                HashMap<String, String> myHashStream = new HashMap<String, String>();
                myHashStream.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_NOTIFICATION));
                myHashStream.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "1");

                mTTS.setLanguage(Locale.US);
                //mTTS.setOnUtteranceCompletedListener(this);
                mTTS.speak("I'm saying some stuff to you!", TextToSpeech.QUEUE_FLUSH, myHashStream);        
            }

        }).start();*/

        //I've tried it not in a thread...
        HashMap<String, String> myHashStream = new HashMap<String, String>();
        myHashStream.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_NOTIFICATION));
        myHashStream.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "1");

        mTTS.setLanguage(Locale.US);
        mTTS.setOnUtteranceCompletedListener(this);
        mTTS.speak("I'm saying some stuff to you!", TextToSpeech.QUEUE_FLUSH, myHashStream);    

    }

    @Override
    public IBinder onBind(Intent intent) {

        return null;
    }

    @Override
    public void onInit(int status) {
        Log.d("", "TTSService onInit: " + String.valueOf(status));
        if(status == TextToSpeech.SUCCESS){
            Log.d("", "TTS Success");
        }
    }

    public void onUtteranceCompleted(String uttId) {
        Log.d("", "done uttering");
        if(uttId == "1") {
            mTTS.shutdown();
        }

    }

}

Thanks

  • 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-27T03:07:32+00:00Added an answer on May 27, 2026 at 3:07 am

    Ok, I’ve got it figured out now! What was happening is it was trying to speak before TTS was initialized. So in a thread I wait for ready to not == 999. Once its either 1 or anything else we’ll then take care of speaking. This might not be safe putting it in a while loop but… It’s working nonetheless.

    import java.util.HashMap;
    import java.util.Locale;
    
    import android.app.Service;
    import android.content.Intent;
    import android.media.AudioManager;
    import android.os.IBinder;
    import android.speech.tts.TextToSpeech;
    import android.speech.tts.TextToSpeech.OnInitListener;
    import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
    import android.util.Log;
    
    public class TTSService extends Service implements OnInitListener, OnUtteranceCompletedListener {
    TextToSpeech mTTS;
    int ready = 999;
        @Override
        public void onCreate() {
    
            Log.d("", "TTSService Created!");
            mTTS = new TextToSpeech(getApplicationContext(), this);
    
            new Thread(new Runnable() {
                @Override
                public void run() {
                    while(ready == 999) {
                        //wait
                    }
                    if(ready==1){
                    HashMap<String, String> myHashStream = new HashMap<String, String>();
                    myHashStream.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_NOTIFICATION));
                    myHashStream.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "1");
    
                    mTTS.setLanguage(Locale.US);
                    //mTTS.setOnUtteranceCompletedListener(this);
                    mTTS.speak("I'm saying some stuff to you!", TextToSpeech.QUEUE_FLUSH, myHashStream);
    
                    } else { 
                        Log.d("", "not ready"); 
                        }
                }
    
            }).start();
    
    
            stopSelf();
    
        }
    
        @Override
        public IBinder onBind(Intent intent) {
    
            return null;
        }
    
        @Override
        public void onDestroy() {
            mTTS.shutdown();
            super.onDestroy();
        }
        @Override
        public void onInit(int status) {
            Log.d("", "TTSService onInit: " + String.valueOf(status));
            if (status == TextToSpeech.SUCCESS)
            {
                ready = 1;
    
            } else {
                ready = 0;
                Log.d("", "failed to initialize");
            }
    
        }
    
        public void onUtteranceCompleted(String uttId) {
            Log.d("", "done uttering");
            if(uttId == "1") {
                mTTS.shutdown();
            }
    
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns 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.