Playing TTS Output via Media Player

0

I am trying to play audio of TextToSpeech output with mediaPlayer. Sometimes it works but I am getting these errors mostly. What is the main problem on that method ? - Prepare failed.: status=0x1 - setDataSourceFD failed.: status=0x80000000

private void speak(String message)
{
    MediaPlayer mediaPlayer = new MediaPlayer();
    File root = android.os.Environment.getExternalStorageDirectory();
    File dir = new File(root.getAbsolutePath() + "/download");
    File soundFile = new File(dir, "myData.mp3");

    try
    {
        int test = myTTS.synthesizeToFile(message, null, soundFile, "tts");
        System.out.println("TEST   : "+test);

        mediaPlayer.stop();
        mediaPlayer.reset();
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setDataSource(soundFile.getPath());
        mediaPlayer.prepare();
        mediaPlayer.start();
        System.out.println("DURATION  :          "+ mediaPlayer.getDuration() );
    }
    catch (IOException ioe)
    {
        System.out.println("ERROR:    " +ioe.getLocalizedMessage());
        soundFile.deleteOnExit();
    }        
}
android
android-mediaplayer
text-to-speech
audioformat
asked on Stack Overflow Mar 10, 2020 by Gökhun Çelik • edited Mar 10, 2020 by Gökhun Çelik

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0