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

The Archive Base Latest Questions

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

public boolean playing=false; private void prepareTTSEngine() { try { synthesis = SpeechSynthesis.getInstance(this); synthesis.setSpeechSynthesisEvent(new SpeechSynthesisEvent()

  • 0
 public boolean playing=false;
  private void prepareTTSEngine() {
        try {
            synthesis = SpeechSynthesis.getInstance(this);


            synthesis.setSpeechSynthesisEvent(new SpeechSynthesisEvent() {

                public void onPlaySuccessful() {
                    Log.i(TAG, "onPlaySuccessful");
                    playing=true;

                }

                public void onPlayStopped() {
                    Log.i(TAG, "onPlayStopped");
                    playing=false;

                }

                public void onPlayFailed(Exception e) {
                    Log.e(TAG, "onPlayFailed");
                    e.printStackTrace();
                    playing=false;
                }

                public void onPlayStart() {
                    Log.i(TAG, "onPlayStart");
                    //playing=true;

                }

                @Override
                public void onPlayCanceled() {
                    Log.i(TAG, "onPlayCanceled");
                    playing=false;
                }


            });

            //synthesis.setVoiceType("usenglishfemale1"); // All the values available to you can be found in the developer portal under your account

        } catch (InvalidApiKeyException e) {
            Log.e(TAG, "Invalid API key\n" + e.getStackTrace());
            Toast.makeText(_context, "ERROR: Invalid API key", Toast.LENGTH_LONG).show();
        }

    }

         prepareTTSEngine();
        String speech= MapLocationOverlay.mSelectedMapLocation.getShortDesc();
        synthesis.setVoiceType("usenglishfemale");

        BreakIterator iterator = BreakIterator.getSentenceInstance(Locale.US);
        iterator.setText(speech);
        int start = iterator.first();

        for (int end = iterator.next();end != BreakIterator.DONE; start = end, end = iterator.next()) {
            if(speech !=null && speech.substring(start,end).compareTo("")!=0)
            {
                String sentence_next=speech.substring(start,end);                   
                        //set ready flag to true (so isReady returns true) 


                while(playing==true)
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                            try {
                                synthesis.speak(sentence_next);
                            } catch (BusyException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (NoNetworkException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }


enter code here


            }
        }
    }

I'm using [the iSpeech library'sSpeechSynthesisclass](http://www.ispeech.org/androidsdkdoc/com/ispeech/SpeechSynthesis.html). When I call thespeakmethod in afor`-loop, passing one sentence at a time, all of the sentences start at once. I guess this is because the method is non-blocking. It’s not open-source, so I can’t see how it works. How can I make it so that it doesn’t start one sentence until the previous sentence is done?

  • 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-31T12:21:35+00:00Added an answer on May 31, 2026 at 12:21 pm

    Usually with those kinds of libraries, the code doesn’t wait for the sound to stop playing (for good reasons).

    From the documentation of your library, it seems that you should listen for SpeechSynthesisEvent with PLAY_SUCCESSFUL before reading the next sentence.

    If it suits your needs the javax.speech.synthesis has a rather simple mechanism to wait until the speech is done, check it out: http://java.sun.com/products/java-media/speech/forDevelopers/jsapi-guide/Synthesis.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code for update: public Boolean update() { try { data.put(ContactsContract.Groups.SHOULD_SYNC, true);
public boolean requestRouteToHost (int networkType, int hostAddress) This method in ConnectivityManager if used with
Having this method: public Boolean isCorrect() { return correct; } I can't write: @XmlType(propOrder
I add this code in my activity public boolean onKeyDown(int keyCode, KeyEvent event) {
i have written a method in java like this public boolean ADD(String ID,String Name,String
I have two arrays: Walls and Neighbors. public boolean[] walls = new boolean[4]; public
Why doesn't this code compile? public boolean isOf(Class clazz, Object obj){ if(obj instanceof clazz){
myEdit1.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { myEdit2.setText(); return
I'm new to C#, so forgive this noobish question. I'm playing with a simple
I have the following problem: public Boolean Exists(String userName) { IRepository<User> = new UserRepository();

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.