Code example for TextToSpeech

Methods: synthesizeToFile

0
      HashMap<String, String> params = new HashMap<String, String>();
      params.put(Engine.KEY_PARAM_UTTERANCE_ID, "" + curText);
      File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
      dir.mkdirs();
      d("synthesizing " + texts[curText].substring(0,50) + "...");
      if (tts.synthesizeToFile(texts[curText], params, dir + "/tts" + curText + ".wav") != TextToSpeech.SUCCESS) {
        throw new RuntimeException();
      } 
      curText++;
    } else { 
      d("finished"); 
    } 
  } 
 
  @Override 
  public void onDestroy() { tts.shutdown(); super.onDestroy(); }
} 
 
// vim: et sw=2 ts=2