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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:19:56+00:00 2026-05-26T20:19:56+00:00

How to Integrate Text to Speech Functionality? Following is my code:- public class TtsActivity

  • 0

How to Integrate Text to Speech Functionality?

Following is my code:-

public class TtsActivity extends Activity implements OnInitListener {

    private int MY_DATA_CHECK_CODE = 0;

    private TextToSpeech tts;

    private EditText inputText;
    private Button speakButton;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        inputText = (EditText) findViewById(R.id.input_text);
        speakButton = (Button) findViewById(R.id.speak_button);

        speakButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = inputText.getText().toString();
                if (text != null && text.length() > 0) {
                    Toast.makeText(TtsActivity.this, "Saying: " + text,
                            Toast.LENGTH_LONG).show();
                    tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                }
            }
        });

        Intent checkIntent = new Intent();
        checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
        startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == MY_DATA_CHECK_CODE) {
            System.out.println("Code is:- " + requestCode);
            System.out.println("Code is:- " + resultCode);
            if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
                System.out.println("Code is:- " + resultCode);
                // success, create the TTS instance
                tts = new TextToSpeech(this, this);
            } else {
                System.out.println("Code is:- " + resultCode);
                // missing data, install it
                Intent installIntent = new Intent();
                installIntent
                        .setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                startActivity(installIntent);
            }
        }

    }

    @Override
    public void onInit(int status) {
        if (status == TextToSpeech.SUCCESS) {
            Toast.makeText(TtsActivity.this,
                    "Text-To-Speech engine is initialized", Toast.LENGTH_LONG)
                    .show();
        } else if (status == TextToSpeech.ERROR) {
            Toast.makeText(TtsActivity.this,
                    "Error occurred while initializing Text-To-Speech engine",
                    Toast.LENGTH_LONG).show();
        }
    }
}

if i run above code the Google android market is open and if i install the application then the text to speech is work complete but if i not install the application the error is occured.

So, Please Help Me.

  • 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-26T20:19:57+00:00Added an answer on May 26, 2026 at 8:19 pm

    That is because Text To Speech needs TTS engine on your device.If you don’t have that installed on your device,it will redirect you to market and let you download the same.So after you install that engine,your app would find TTS Engine and works fine on your device.

    For more reference,please visit:

    http://www.jameselsey.co.uk/blogs/techblog/android-a-really-easy-tutorial-on-how-to-use-text-to-speech-tts-and-how-you-can-enter-text-and-have-it-spoken/

    EDIT :

    TextToSpeech mTts;
    mTts = new TextToSpeech(this,
                this  // TextToSpeech.OnInitListener
                );
    ...
    mTts.setPitch(2.3); //change it as per your need
    ...
    mTts.speak(s,TextToSpeech.QUEUE_FLUSH,null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how to share a text viz twitter,i used this code to integrate
I was provided the following code to integrate into my ASP.NET WebForms page: <form
I'm trying to integrate a public message board service into an existing web site.
I have a table in SQL Server with the following columns: id int (primary
I am currently trying to integrate a RIch Text Editor in an application I
how i integrate html text editor in windows application?
I have to take a bunch of columnar text files and integrate them into
I am trying to integrate my timesheets app with Fogbugz by using a text
In my .zshrc , I use the following snippet to integrate the shell's clipboard
I want to integrate full-text search into a .NET application with [Fluent] NHibernate-based data

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.