// festival2phone.c // simple program to convert words into their phonemes // the program uses festival to do the hard work // to compile execute "gcc festival2phone.c -o festival2phone" // Festival should be configured to use the required language // (this is normally done in file /usr/share/festival/voices.scm // in the variable defvar default-voice-priority-list) // This program is under GNU license // Developed by ubanov for VoxForge (2008) #include #include int Festival2Lex(char *word,FILE *sal) { char buf[1024],buf2[1024],*punt; FILE *fich; if(sal==NULL) sal=stdout; sprintf(buf,"echo \"(lex.lookup \\\"%s\\\")\" | festival -i --pipe",word); if((fich=popen(buf,"r"))==NULL) /* execute festival with a pipe */ return -1; buf2[0]=0; /* init buf2 to empty */ fgets(buf,sizeof(buf),fich); /* get first line */ while(!feof(fich)) { /* while more lines... */ if(strchr(buf,'>') && buf2[0]==0) /* store first line containing > char */ strcpy(buf2,strchr(buf,'>')+1); fgets(buf,sizeof(buf),fich); /* get next line */ } pclose(fich); /* close the pipe */ if(buf2[0]==0) /* if there is no line with >, exit */ return -2; if(!strchr(buf2,'(')) /* search first ( */ return -3; punt=strchr(buf2,'(')+1; if(!strchr(punt,'(')) /* search second ( */ return -3; punt=strchr(punt,'(')+1; /* now punt points to ((p r o) 0) ((b a1 n) 1)) */ while(*punt!=')') { punt+=2; while(*punt!=')') /* printf silabe */ fprintf(sal,"%c",*punt++); fprintf(sal," "); /* now blank space to separate silabes */ if(strchr(punt+1,')')) punt=strchr(punt+1,')')+1; while(*punt==' ') /* jump spaces, until next valid character */ punt++; } return 0; } int main(int nargs,char *args[]) { int a; if(nargs==1) { printf("Usage: festival2phone word1 [word2 [word3...]]\n"); return -1; } for(a=1;a