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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:56:37+00:00 2026-06-18T06:56:37+00:00

I am using the following code to store Text to Speech output as wav

  • 0

I am using the following code to store Text to Speech output as wav file in my application. I am not sure where is the error, can you please take a look into that and suggest me?

public class MainActivity extends Activity {

Button store, play;
EditText input;
String speakTextTxt;
TextToSpeech mTts;
HashMap<String, String> myHashRender = new HashMap<String, String>();
String tempDestFile ;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    store = (Button) findViewById(R.id.button1);
    play = (Button) findViewById(R.id.button2);
    input = (EditText) findViewById(R.id.editText1);
    store.setOnClickListener(new OnClickListener()  {

        public void onClick(View v) {
            speakTextTxt = "Hello world Hello world Hello world Hello world Hello world Hello world Hello world Hello world Hello world Hello world Hello world";
            HashMap<String, String> myHashRender = new HashMap<String, String>();
            myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, speakTextTxt);

            String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();

            File appTmpPath = new File(exStoragePath + "/sounds/");
            appTmpPath.mkdirs();

            String tempFilename = "hello.mp3";

            tempDestFile = appTmpPath.getAbsolutePath() + "/" + tempFilename;

            new MySpeech(speakTextTxt);


        }
    });
}

class MySpeech implements OnInitListener
{

            String tts;

    public MySpeech(String tts)
    {
        this.tts = tts;
        mTts = new TextToSpeech(MainActivity.this, this);
    }

    @Override
    public void onInit(int status) 
    {
        Log.v("log", "initi");
        int i = mTts.synthesizeToFile(speakTextTxt, myHashRender, tempDestFile);
        if(i == TextToSpeech.SUCCESS)
        {

          Toast toast = Toast.makeText(MainActivity.this, "Saved "+i,
                Toast.LENGTH_SHORT);
          toast.show();   
        }
        System.out.println("Result : " + i);
    }
  }

 }
  • 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-18T06:56:38+00:00Added an answer on June 18, 2026 at 6:56 am

    referring to the answer of Ted Hopp in this post :

    The important method is synthesizeToFile. It will write the audio to a file on the device that you specify. You can then play that file with a MediaPlayer or you can pull it off the device onto your development system with the adb command-line tool using the command

    EDIT :

    try this code , and then check the path sdcard/ if it contains the file : test.wav

    HashMap<String, String> myHashRender = new HashMap();
    String textToConvert = "this is a demo for saving a WAV file";
    String destinationFileName = "/sdcard/test.wav";
    myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, textToConvert);
    mTts.synthesizeToFile(textToConvert, myHashRender, destinationFileName);
    

    EDIT 2 :

    and if you are trying to save the wave file to the internal memory ( not the /sdcard/folder) , then the only way to achieve this is to create a world writable
    directory in the internal memory like this:

    context.getDir("soundfiles", Context.MODE_WORLD_WRITEABLE);
    

    And then write to this dir.

    EDIT 3 :

    after taking a look into your code , you’ve just some problems with creating directories and files : the code should be like this :

    speakTextTxt = "Hello world";
    HashMap<String, String> myHashRender = new HashMap<String, String>();
    myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, speakTextTxt);
    
    String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
    Log.d("MainActivity", "exStoragePath : "+exStoragePath);
    File appTmpPath = new File(exStoragePath + "/sounds/");
    boolean isDirectoryCreated = appTmpPath.mkdirs();
    Log.d("MainActivity", "directory "+appTmpPath+" is created : "+isDirectoryCreated);
    String tempFilename = "tmpaudio.wav";
    tempDestFile = appTmpPath.getAbsolutePath() + File.separator + tempFilename;
    Log.d("MainActivity", "tempDestFile : "+tempDestFile);
    new MySpeech(speakTextTxt);
    

    i’ve tested it on android emulator , and it works fine , but you need to specify the size of the sdCard of your emulator bye using device manager, edit eumlator, and specify the size of your sdcard : example 512 Mb. and then you will find the wav file in the path : mnt/sdcard/sounds/tmpaudio.wav
    to test it , just open the DDMS perspective, File Explorer, and then export the file to your PC .

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

Sidebar

Related Questions

I am using the following tcl code to store a file from my deskstop
I'm creating a console application to read a local file using the following code:
I am using the following code: if (store.getItem('TopicID') != 00) TopidID is always 4
I am using the following code to store values in aspx session. Code: $(div.menu_body
Using following code I try to get updated list of checkbuttons' corresponding text values,
How can I unpack a 4byte binary file, store like the following example, to
In my application I am using the following code to save images/files into the
hi all: making a sample application in which we can store data on File
I have the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using
I am using the following code to store a person's information from a grid

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.