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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:03:21+00:00 2026-05-31T15:03:21+00:00

I am trying to implement text to speech technology of android in my Activity

  • 0

I am trying to implement text to speech technology of android in my Activity but I face a strange error. I can’t hear any sound, from my code. The speak method works only if I place it in onInit method, else it doesn’t speak.

My code is as follows :

public class GameOverActivity extends Activity implements OnInitListener {
private TextToSpeech talker;
....
talker = new TextToSpeech(this, this);  
say("Something",false);
...
   public void onInit(int status) {  
        if (status == TextToSpeech.SUCCESS) {
          talker.setLanguage(Locale.US);
        }
        else if (status == TextToSpeech.ERROR) {
            Toast.makeText(this,"Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();
        }

void say(String text, boolean flush) {
         if(flush == true)
         {
        talker.speak(text,TextToSpeech.QUEUE_FLUSH,null);
         }
         if(flush == false)
         {
        talker.speak(text,TextToSpeech.QUEUE_ADD,null);
         }         
    }

The strange thing is that if I place the say method in onInit, it works fine!

I watched logcat carefully and here are the results :

TtsService.OnCreate ()
TTs is loading
AudioTrack started
TTSService.setLanguage
loaded en-US succusfully
setting speech rate to 100

and then nothing happens.

Any idea about what is wrong with the above code?

Thanks in advance!

  • 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-31T15:03:22+00:00Added an answer on May 31, 2026 at 3:03 pm

    After some more hours looking the code, I noticed that the problem is that TTS engine initialization takes some time. If initialization is not over, the speak method call will fail.

    If you “say” something on button click, you will probably won’t need this, because user will take some time to think before pressing the button, and the initialization will be over.

    If you want to “say” something as soon initialization finishes, use this code :

    talker = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
    
            @Override
            public void onInit(int arg0) {
           if(arg0 == TextToSpeech.SUCCESS) 
               {
            talker.setLanguage(Locale.US);
                say(gameover,true);
                say(line,false);
                say(definition_string,false);
                }
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement text to speech by following this article on the
I'm trying to implement #field_prefix on a text field so I can add some
I am trying to implement an interface where users can dynamically enter text and
I am trying to implement full text search using Quartz 2D but it's a
Trying to implement the new FP 10.1 Global error handler into my projects but
I am trying to implement a djapian based full text search for searching user
I am trying to implement a control to edit text that will display the
I am trying to implement a wpf user control that binds a text box
I am new to WinForms. When I am trying to implement the masked text
I'm trying to implement a simple watermark on a text box that disappears when

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.