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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:24:25+00:00 2026-06-01T05:24:25+00:00

I used the following code to convert text to speech. In my code i

  • 0

I used the following code to convert text to speech. In my code i stored the user input as .wav format. While i execute this code, every thing works fine, when i play the file it won’t play.

TTS_AudioActivity.java

public class TTS_AudioActivity extends Activity implements OnInitListener {

    private int MY_DATA_CHECK_CODE = 0;

    private TextToSpeech tts;
    String destFileName = "/sdcard/wakeUp.wav";
    private EditText inputText;
    private Button speakButton, listen;

    @Override
    public void onCreate(Bundle savedInstanceState) {

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

        inputText = (EditText) findViewById(R.id.editText1);
        speakButton = (Button) findViewById(R.id.button1);
        listen = (Button) findViewById(R.id.button2);
        speakButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = inputText.getText().toString();
                if (text != null && text.length() > 0) {

                    HashMap<String, String> myHashRender = new HashMap();
                    myHashRender.put(
                            TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, text);
                    tts.synthesizeToFile(text, myHashRender, destFileName);

                    Toast.makeText(TTS_AudioActivity.this, "Saying: " + text,
                            Toast.LENGTH_LONG).show();
                     tts.speak(text, TextToSpeech.QUEUE_ADD, null);
                }
            }
        });

        listen.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                if (!Environment.getExternalStorageState().equals(
                        Environment.MEDIA_MOUNTED)) {

                } else {

                    MediaPlayer mpPlayProgram = new MediaPlayer();
                    try {
                        mpPlayProgram
                                .setDataSource("/sdcard/wakeUp.wav");
                        mpPlayProgram.prepare();
                        mpPlayProgram.start();
                        mpPlayProgram.release();

                    } catch (IllegalArgumentException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IllegalStateException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }

                // MediaPlayer mpPlayProgram = new MediaPlayer();
                // try {
                // mpPlayProgram.setDataSource(destFileName);
                // mpPlayProgram.prepare();
                // mpPlayProgram.start();
                // mpPlayProgram.release();
                //
                // } catch (IllegalArgumentException e) {
                // // TODO Auto-generated catch block
                // e.printStackTrace();
                // } catch (IllegalStateException e) {
                // // TODO Auto-generated catch block
                // e.printStackTrace();
                // } catch (IOException e) {
                // // TODO Auto-generated catch block
                // e.printStackTrace();
                // }

                // tts.addSpeech(null, "/sdcard/wakeUp.wav");
            }
        });

        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) {
            if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
                // success, create the TTS instance
                // tts.isLanguageAvailable(Locale.ENGLISH);
                tts = new TextToSpeech(TTS_AudioActivity.this, this);
            } else {
                // 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(TTS_AudioActivity.this,
                    "Text-To-Speech engine is initialized", Toast.LENGTH_LONG)
                    .show();
        } else if (status == TextToSpeech.ERROR) {
            Toast.makeText(TTS_AudioActivity.this,
                    "Error occurred while initializing Text-To-Speech engine",
                    Toast.LENGTH_LONG).show();
        }
    }

}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="54dp"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="42dp"
        android:text="Save" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@+id/button1"
        android:layout_marginTop="32dp"
        android:text="Play" />

</RelativeLayout>

Here i stored the file in sdcard. When i play file from sdcard it won’t play. How can i play the file.

  • 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-06-01T05:24:26+00:00Added an answer on June 1, 2026 at 5:24 am

    The call to release is the problem.

    You called release() just after start().
    You better call release() when you are done with the MediaPlayer, as said in the documentation : http://developer.android.com/reference/android/media/MediaPlayer.html

    You should read carefully this documentation, because MediaPlayer is kind of a complicated thing (in my opinion).

    By the way, you should access your sdcard by using Environment.getExternalStorageDirectory() and going through the files hierarchy from that call.

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

Sidebar

Related Questions

In the following code, I used NSClassFromString to convert say an NSString ColorFilter to
I have used the following code. This code works sometime but sometime not works.
I used following code, but it displays only 2 digit of ISO country name.
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as
I have used following code to create a simple PDF file. It executes fine
I am trying to used following code but I am not getting good performance
I've used following code snippet for my activity in order to deal with orientation
I've used following code for parsing XML file in c++. http://www.codeproject.com/Articles/176236/Parsing-an-XML-file-in-a-C-C-program . Now I
I used following JS code to create equal height columns: var colHeight = Math.max($('.3columngallery
I used the following code to get the path Path errorFilePath = FileSystems.getDefault().getPath(errorFile); 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.