/* readword.c read word aloudly with realpeople TTS * Copyright (c) 2004 by SmartLu All Rights Reserved * Distributed under the terms of the GNU General Public License (GPL) * See the GNU Library General Public License for more details. */ #include #include #include #include #include "srecite.h" // judge whether can read or not static gboolean can_readword(gchar * word); // read good word checked static void read_good_word(gchar * word); static gboolean have_data_file = 0; static gboolean have_fest_tts = 0; // judge whether can read or not static gboolean can_readword(gchar * word) { gboolean return_val = 0; int n=0,i; if(have_data_file && word && g_ascii_isalpha(word[0])) { gchar *lowerword = (gchar *)g_malloc(n+1); gchar *filename; n=strlen(word); for (i=0;i < n;i++) { lowerword[i]= g_ascii_tolower(word[i]); } lowerword[n] = '\0'; filename = g_strdup_printf( RP_TTS_DIR"%c/%s.wav", lowerword[0],lowerword); return_val = g_file_test(filename, G_FILE_TEST_EXISTS); g_free(filename); g_free(lowerword); } if(return_val == 0 && S_conf.pronounce == 1 ) g_print("Can't read word:(%s), try to use tts!\n",word); return return_val; } // read aloudly with TTS static void read_good_word(gchar * word) { int n,i; if (word && g_ascii_isalpha(word[0])) { gchar *lowerword = (gchar *)g_malloc(n+1); gchar *filename; int fd; n=strlen(word); for (i=0;i < n;i++) { lowerword[i]= g_ascii_tolower(word[i]); } lowerword[n] = '\0'; filename = g_strdup_printf( RP_TTS_DIR"%c/%s.wav", lowerword[0],lowerword); //gnome_sound_play(filename); fd = esd_open_sound(NULL); if (fd >= 0) { esd_play_file(NULL,filename, 0); esd_close(fd); } else g_print("Device busy or Can't support esd !\n"); g_free(filename); g_free(lowerword); } } // read aloudly with TTS void read_word(gchar * word) { have_data_file = g_file_test(RP_TTS_DIR, G_FILE_TEST_EXISTS); have_fest_tts = g_file_test(FEST_TTS_DIR, G_FILE_TEST_EXISTS); if(S_conf.pronounce == 1) { if((have_data_file == 0) && (have_fest_tts == 0)) { g_print("Not found TTS (%s) and (%s)!\nOff pronounce switch!\n",RP_TTS_DIR,FEST_TTS_DIR); S_conf.pronounce = 0; } //read if(can_readword(word) ) read_good_word(word); else tts_read(word); } } // festival tts read void tts_read(gchar * tts_str) { int pid; FILE *tts_fp=NULL; if(have_fest_tts) { if((tts_fp=fopen("/var/tmp/sr_sound","w")) == NULL) { g_print("Can't open /var/tmp/sr_sound\n"); return; } fprintf(tts_fp,"%s\n",tts_str); fclose (tts_fp); // vfork is child first exec,fork is not sure if((pid = fork() )< 0) perror("fork error\n"); if((pid )== 0) { if(execlp("festival","festival","--tts","/var/tmp/sr_sound",(char *)0) <0) g_print("festival tts is not ok!\n"); else g_print("tts ok!\n"); exit(0); } } else g_print("Not found festival TTS (%s)!\n",FEST_TTS_DIR); //if(waitpid(pid,NULL,0)<0) // perror("error\n"); //perror("noterror\n"); }