#include <string>
#include <admin>
#include "settings"
#include "stringx"
 
#define MAX_SOUND_LENGTH 92
 
stock preparespeech(Msg[]) {
  new DictionaryFile[MAX_DATA_LENGTH];
  new args;
  new Word[MAX_SOUND_LENGTH+2];
  new Sounds[MAX_SOUND_LENGTH+2];
  new Out[MAX_SOUND_LENGTH+2];
  new i;
  new Line[MAX_DATA_LENGTH];
 
  snprintf(Out,MAX_SOUND_LENGTH+2," %s ",Msg);
 
  if (getfilelocation(DictionaryFile,"dictionary.ini")==0) {
    return 0;
  }
 
  strsubst(Out," ( ","(",MAX_SOUND_LENGTH);
  strsubst(Out," )",")",MAX_SOUND_LENGTH);
  new ReadCount = filesize(DictionaryFile)+1;
 
  for(i=0;i<ReadCount;i++) {
    /* File line numbers are indexed from 1, not 0, hence the +1 */
    readline(DictionaryFile,i,Line);
 
    args=strsplit(Line,"=",Word,MAX_SOUND_LENGTH,Sounds,MAX_SOUND_LENGTH);
    if (args==2) {
      snprintf(Word,MAX_SOUND_LENGTH+2," %s ",Word);
      snprintf(Sounds,MAX_SOUND_LENGTH+2," %s ",Sounds);
      strsubst(Out,Word,Sounds,MAX_SOUND_LENGTH+2);
    }
  }
 
 
  strtrim(Out," ",2);
/*  snprintf(Line,MAX_DATA_LENGTH,"Mapped ^"%s^" to ^"%s^"",Msg,Out);
  log(Line);*/
  strcpy(Msg,Out,MAX_SOUND_LENGTH);
  return 1;
}